Link to home
Start Free TrialLog in
Avatar of mac-will
mac-willFlag for Canada

asked on

Win Form DataTable Display Properties

Hello all,

I have a DataGridView that is bound to a BindingSource.  I do some manual processing and create several DataTables I then set the datasource of the BindingSource to the desired DataTable.

This works well and the DataGridView updates and displays the data I want to display.

What I am looking for is a way to associate display properties, such as column width, with each datatable.

So for example if DataTable_1 has 3 columns; "c1", "c2", "c3"  and DataTable_2 has 2 columns: "b1", "b2"

I want to be able to associate properties like c1's width is 25px so that when I set the DataSource to DataTable_1  I don't have to iterate through the columns of the DataGridView and set each column property.

Any ideas?

Thanks,

MAC
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Honestly I don't quite understand the question. Because there are now width properties for DataColumn class you need to set widt for the DataGridView  somehow. And you need to set it explicitly for each column. I can't see any other way. You may create a procedure that e.g. count a number of columns and sets width according to this number, or you may store this width somewhere else but anyway you need to set this width explicitly column by column. Or I miss something?
Avatar of mac-will

ASKER

I guess the question boils down to: Can you store a column width and/or hidden property in a DataTable such that a DataGridView will automatically display the dataTable this way?

Sounds like it is not possible which would mean when I change the DataTable I will need to iterate through the DataGridView columns and set their properties individually.
ASKER CERTIFIED SOLUTION
Avatar of Dmitry G
Dmitry G
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.

This isn't quite automatic but this definitely will work as a work around.

MAC