I have a DataGridView that has three read only columns in it and one or several other writable columns. The users have decided they need to be able to reorder the columns. I need a way to allow them them to reorder the writable columns but not the read only ones. The only thing I have thought of is to check if the column that was just moved in the ColumnDisplayIndexChanged event is read only, check it's name and then move it back to where I want it. I don't like that solution. Does anyone have a more elegant solution to this problem?
If column reordering is enabled, the frozen columns are treated as a group distinct from the unfrozen columns. Users can reposition columns in either group, but they cannot move a column from one group to the other.
Does this sound like what you want?
http://msdn.microsoft.com/en-us/library/28e9w2e1.aspx
You could disable column reordering by default, and only enable it when the mouse cursor is over a column that you want to be moved.
Not that I actually tried this, but it's worth a try.
Related
In my WPF application, I am using a DataGrid control. I allow the user to reorder columns. However, I have to ensure that the first two columns and the last column cannot be reordered.
All the columns are generated programmatically using new DataGridTextColumn().
I am wondering if someone can guide me on what I need to do to accomplish this? Thank you in advance for your help.
You can use the DataGrid.FrozenColumnCount Property to not allow the users to move columns.
However, if you look at the documentation, you will see that you can only do this for the first x columns from the left side of the DataGrid. For example, if you set the FrozenColumnCount to 2, the two left columns in the display are frozen.
Use DataGridColumn.CanUserReorder property (set tis property to false for columns, which can't be reordered).
I'm pretty much to C# and I'm trying to create a simple network analyzer. I want to be able to see packets in a datagridview. The imagined lay-out can be compared with tools like wireshark. I would like my datagridview to always be "filled". By filled I mean that it always contains rows even if these are empty.
When starting the application for example I would like the grid to be fully filled with rows. The total height of the gridView is a multiple of the row height, so it contains enough rows so it's exactly 100% filled. When adding data however I would like that these empty rows do not count so data overwrites these empty rows, and when removed these rows return if otherwise the DataGridView would not be fully filled. I realize I might explain this a bit poorly but I'm not sure how I could try to bring across what I mean otherwise. The way Excel works would be ideal for example. You start with a full screen with empty cells, and you can add things to them. If you add more data than fits a scoll bar gets introduced to still be able to see all data. When you remove it the scrollbar becomes smaller until eventually it's not needed anymore but the cells remain shown. (even if empty)
Thanks in advance,
Arnold
-edit-
Regarding height of things: I'd probably want things to be resizable in the future. So that information could probably not be exploited.
Wrap a DataGridView with a user control to override adding and removing rows.
If you are removing a row - it must be real (not marked as "place holder" [tag?]).
and if your Count is less than IdealCount, add a "place holder" row.
If you are adding a row - if your Count is less than IdealCount, remove the last "place holder" row.
Initialize with IdealCount number of "place holder" rows.
Let the rows be sorted by a hidden column of default value 0 and a value of 1 for "place holders" or simply maintain the rows order yourself in the Add override. This way the "place holders" will always be last (and there won't be any, if Count > IdealCount).
I want the user to submit a message, and that message will be automatically added as a table row. Is it possible?
I want to do this:
Table table=new Table. table.Rows.Add(row)
Then I want to be able to insert a label into that row. For example:
row.Add(table)
But I can't find a way to do that.
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.table.aspx
I want the table to grow one row bigger than it used to be with a label of the users newly added message.
I know that forums use tables, but their table seems to be growing with every message submitted.
How can I achieve the same effect with C#?
You did not provide enough details to say for sure, but almost absolutely yes.
If the HTML is dynamically and explicitly generated by you, then yes. Insert it in there.
If you are using a non-constant DataSource, then yes. Insert it in there.
The only reason it would not be possible is if the page is static, or if the data source is constant. And both of those are changeable.
I have a DataGridView (with WinForms) where I'm treating a particular row as a "child" of the row just before it. This means when a user sorts a column, that child row as to stay attached to the parent so it always appears just below it.
I'm overriding the SortCompare method to handle this, but I'm not sure just how to do it. Within SortCompare, I know if the row has a parent row, and if so what that row is. Therefore I want to be able to say, "if row1 has a parent, let the sort result be whatever it would be comparing row1's parent to row2". But how do I accomplish that without explicitly comparing the values myself (which I want to avoid so I don't have to keep track of the data types)? Is the comparer it's using available anywhere? Or is there just a better way to do what I'm trying to accomplish?
Set SortExpression on the column to any valid column name. It does not have to be itself
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sortexpression.aspx
I'm guessing you want small groups. Have you looked at the custom DataGridViewGrouper component ?
You could have distinct properties for each row group and use this custom component to create your groups. Each two-row group would have a distinct property that would allow you to group them together. To me, you would have to somehow distinguish individual groups through a distinct tag or property. There is no parent-child relationship in this case, though I don't see that is important since you want to group them.
I have an app that lets the user reorder columns in a DataGridView, and I want to save the "layout" upon closing the app...but it seems that when I iterate through the column collection, I get them in the order I added them, not the order they appear on screen. Is there a way to get the displayed ordering?
edit: found it, just check the DisplayIndex property of each column :)
You'll have to use the DataGridViewColumn.DisplayIndex property. http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcolumn.displayindex.aspx