hide data grid columns
-
I just want to hide some columns on my data grid (dynamically). I have my data grid, it's loading the data just fine, and all I want to do is make a column hidden. Here's what I wrote: this.dgClaimsExperience.Columns(1).Visible = false; But C# tells me that System.Windows.Forms.DataGrid does not contain a definition for columns. So... how do I do it? Thanks. The ends can never justify the means. It is the means that determine the ends.
-
I just want to hide some columns on my data grid (dynamically). I have my data grid, it's loading the data just fine, and all I want to do is make a column hidden. Here's what I wrote: this.dgClaimsExperience.Columns(1).Visible = false; But C# tells me that System.Windows.Forms.DataGrid does not contain a definition for columns. So... how do I do it? Thanks. The ends can never justify the means. It is the means that determine the ends.
DataGrid indeed does not contain a columns collection. There are a couple of ways you can handle this, one way is to remove the DataGridColumnStyle for the column you want to hide from DataGrid.TableStyles. The tricky part is that if you want to put it back in it will move to the end of the list and you'll have to rearrange all the other columns (by removing them from the list and then adding them back in the right order). Another way is to set the width of the column (through the DataGridColumnStyle) to zero, but I think the user can still resize it and I think it they can still tab to the column.
-
DataGrid indeed does not contain a columns collection. There are a couple of ways you can handle this, one way is to remove the DataGridColumnStyle for the column you want to hide from DataGrid.TableStyles. The tricky part is that if you want to put it back in it will move to the end of the list and you'll have to rearrange all the other columns (by removing them from the list and then adding them back in the right order). Another way is to set the width of the column (through the DataGridColumnStyle) to zero, but I think the user can still resize it and I think it they can still tab to the column.
Thanks for the suggestions. I think removing the DataGridColumnStyle will work, because in the instance of the form where the data grid is located, I'm never going to want to add the column back in. If you get a chance, post a code snippet for me, otherwise I'm sure I can figure it out on my own. I'd just like to state for the record that I think that DataGrid [i]should[/i] contain a columns collection. It would be useful. Thanks for the help - I'm the only "programmer" (I'm really a mathematical-statistical analyst) in my company so there's no one for me to take my sinple, dumb questions to in person. -stormin The ends can never justify the means. It is the means that determine the ends.
-
Thanks for the suggestions. I think removing the DataGridColumnStyle will work, because in the instance of the form where the data grid is located, I'm never going to want to add the column back in. If you get a chance, post a code snippet for me, otherwise I'm sure I can figure it out on my own. I'd just like to state for the record that I think that DataGrid [i]should[/i] contain a columns collection. It would be useful. Thanks for the help - I'm the only "programmer" (I'm really a mathematical-statistical analyst) in my company so there's no one for me to take my sinple, dumb questions to in person. -stormin The ends can never justify the means. It is the means that determine the ends.
Something like this should work:
DataGridColumnStyle dgcs = MyDataGrid.TableStyles["MyTableName"].GridColumnStyles["MyColumnName"]; MyDataGrid.TableStyles["MyTableName"].GridColumnStyles.Remove(dgcs);
It's a little more efficient if you keep a reference to the table style and column style objects that you're using so that they don't have to be looked up each time, but the above code should work.