M
Mitchell S. Honnert
Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?
Here's the background for my question...
Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one with
a custom set of columns) in the DataGrid.TableStyles property and would use
the DataGrid's ability to switch between these sets of columns depending on
the source data. You could say that the DataGrid's DataGridTableStyle
allowed you to have a set of "context sensitive" columns. If the data
changed, so too did the columns used to view the data.
But when I switched over to the Fx 2.0's DataGridView, I couldn't find an
analog to the DataGridTableStyle. To get the same functionality, whenever I
switch the data source of my DataGridView, I have to clear out the
DataGridView.Columns and add the appropriate columns back. This method
works, but is far less elegant than the way that the old DataGrid works. My
initial idea was to store my sets of custom columns in different
DataGridViewColumnCollection instances and set the DataGridView.Columns
property as appropriate, but the DataGridView.Columns is read-only, so I
couldn't do that.
So, is there an easy way to assign a DataGridView columns in one step or am
I stuck with my current method of clearing and reloading the columns every
time?
Thanks,
- Mitchell S. Honnert
PS: In the MSDN page "Differences Between the Windows Forms DataGridView and
DataGrid Controls" (http://msdn2.microsoft.com/en-us/library/ms171628.aspx),
it says this...
"The only feature that is available in the DataGrid control that is not
available in the DataGridView control is the hierarchical display of
information from two related tables in a single control."
I'm hoping that this statement is true and that I'm just overlooking the
functionality in the DataGridView that equates to the DataGrid's
DataGridTableStyle.
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?
Here's the background for my question...
Before I switched my application over to the Fx 2.0, I used a DataGrid to
display my data. I would store different DataGridTableStyles (each one with
a custom set of columns) in the DataGrid.TableStyles property and would use
the DataGrid's ability to switch between these sets of columns depending on
the source data. You could say that the DataGrid's DataGridTableStyle
allowed you to have a set of "context sensitive" columns. If the data
changed, so too did the columns used to view the data.
But when I switched over to the Fx 2.0's DataGridView, I couldn't find an
analog to the DataGridTableStyle. To get the same functionality, whenever I
switch the data source of my DataGridView, I have to clear out the
DataGridView.Columns and add the appropriate columns back. This method
works, but is far less elegant than the way that the old DataGrid works. My
initial idea was to store my sets of custom columns in different
DataGridViewColumnCollection instances and set the DataGridView.Columns
property as appropriate, but the DataGridView.Columns is read-only, so I
couldn't do that.
So, is there an easy way to assign a DataGridView columns in one step or am
I stuck with my current method of clearing and reloading the columns every
time?
Thanks,
- Mitchell S. Honnert
PS: In the MSDN page "Differences Between the Windows Forms DataGridView and
DataGrid Controls" (http://msdn2.microsoft.com/en-us/library/ms171628.aspx),
it says this...
"The only feature that is available in the DataGrid control that is not
available in the DataGridView control is the hierarchical display of
information from two related tables in a single control."
I'm hoping that this statement is true and that I'm just overlooking the
functionality in the DataGridView that equates to the DataGrid's
DataGridTableStyle.