HighTechTalks DotNet Forums  

databound datagrid can't resize columns, can't disable add new

Dotnet Data Tools microsoft.public.dotnet.datatools


Discuss databound datagrid can't resize columns, can't disable add new in the Dotnet Data Tools forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default databound datagrid can't resize columns, can't disable add new - 04-12-2005 , 06:53 PM






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


Reply With Quote
  #2  
Old   
samitha
 
Posts: n/a

Default RE: databound datagrid can't resize columns, can't disable add new - 05-06-2005 , 06:19 AM






1) What is your originame table name? Is it "ButtonCommandClass". Make sure
you have set the dgStyle.MappingName to the actual table name. Then when
setting the datasource for the datagrid you can specify as follows:

dgAppCommands.DataSource = datasetname.Tables("ButtonCommandClass");
for this you have to fill the dataset with the records from the actual table.

2) One option is to set the ReadOnly property of the datagrid to true. I
think tht's the easiest way to resolve ur prob
hope this helps you

"Omatase (AT) gmail (DOT) com" wrote:

Quote:
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



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.