O
Omatase
I have spent hours on the following two problems:
1 - Resizing a column to a new width
2 - disabling the addnew feature of the datagrid, without making cells
uneditable (i.e. by locking the control)
Here is the data I have on my progress so far:
I think the problems both stem from the fact that although I am using
the datagrid in databound mode, I am not databinding to a datatable. My
datasource is a class that just implements the ibindinglist interface.
Although I got off to a rocky start with the databinding with the
class, that part is working fine now.
Current Problem 1:
I cannot change the widths of the datagrid columns. I have read
numerous posts on this topic and am convinced that since I am not
binding to a datatable I must need to modify the class to which the
grid is bound. Here is the code I have that I am trying to resize the
column widths with.
<code>
dgAppCommands.TableStyles.Clear();
DataGridTableStyle dgStyle = new DataGridTableStyle();
dgStyle.MappingName = "ButtonCommandClass";
DataGridTextBoxColumn dgcStyle1 = new DataGridTextBoxColumn();
DataGridTextBoxColumn dgcStyle2 = new DataGridTextBoxColumn();
dgcStyle1.MappingName = "Button";
dgcStyle2.MappingName = "Command";
dgcStyle2.Width = 25;
dgStyle.GridColumnStyles.Add ((DataGridColumnStyle)dgcStyle1);
dgStyle.GridColumnStyles.Add ((DataGridColumnStyle)dgcStyle2);
dgAppCommands.TableStyles.Add(dgStyle);
</code>
Microsoft says the following in Visual Studio's help file "Set the grid
table object's MappingName to a DataTable object's TableName."
Since I don't have a "DataTable" I don't know what to set the
MappingName to. I have tried putting a property in the class that is
bound to the grid named "TableName" but that didn't work.
Current Problem 2:
I think the reason this doesn't work is also because I am binding to a
class, not a DataTable. Here is the code I have used:
<code>
//no adding of new rows thru dataview...
CurrencyManager cm =
(CurrencyManager)BindingContext[dgAppCommands.DataSource,
dgAppCommands.DataMember];
((DataView)cm.List).AllowNew = false;
</code>
I get a "Specified cast not valid" error on the last line of the above
snippet.
Any help with the above two problems would be greatly appreciated
-Dave
1 - Resizing a column to a new width
2 - disabling the addnew feature of the datagrid, without making cells
uneditable (i.e. by locking the control)
Here is the data I have on my progress so far:
I think the problems both stem from the fact that although I am using
the datagrid in databound mode, I am not databinding to a datatable. My
datasource is a class that just implements the ibindinglist interface.
Although I got off to a rocky start with the databinding with the
class, that part is working fine now.
Current Problem 1:
I cannot change the widths of the datagrid columns. I have read
numerous posts on this topic and am convinced that since I am not
binding to a datatable I must need to modify the class to which the
grid is bound. Here is the code I have that I am trying to resize the
column widths with.
<code>
dgAppCommands.TableStyles.Clear();
DataGridTableStyle dgStyle = new DataGridTableStyle();
dgStyle.MappingName = "ButtonCommandClass";
DataGridTextBoxColumn dgcStyle1 = new DataGridTextBoxColumn();
DataGridTextBoxColumn dgcStyle2 = new DataGridTextBoxColumn();
dgcStyle1.MappingName = "Button";
dgcStyle2.MappingName = "Command";
dgcStyle2.Width = 25;
dgStyle.GridColumnStyles.Add ((DataGridColumnStyle)dgcStyle1);
dgStyle.GridColumnStyles.Add ((DataGridColumnStyle)dgcStyle2);
dgAppCommands.TableStyles.Add(dgStyle);
</code>
Microsoft says the following in Visual Studio's help file "Set the grid
table object's MappingName to a DataTable object's TableName."
Since I don't have a "DataTable" I don't know what to set the
MappingName to. I have tried putting a property in the class that is
bound to the grid named "TableName" but that didn't work.
Current Problem 2:
I think the reason this doesn't work is also because I am binding to a
class, not a DataTable. Here is the code I have used:
<code>
//no adding of new rows thru dataview...
CurrencyManager cm =
(CurrencyManager)BindingContext[dgAppCommands.DataSource,
dgAppCommands.DataMember];
((DataView)cm.List).AllowNew = false;
</code>
I get a "Specified cast not valid" error on the last line of the above
snippet.
Any help with the above two problems would be greatly appreciated
-Dave