Z
zelaumbr
Guest
Hi, Im having a stranger problem with datagridview and dynamic column
C yyyyy Red Maple New
C yyyyy Red Maple New Red Maple New
C yyyyy Red Maple New
Continue reading...
Im using:
C# and Visual Studio 2005
The problem:
I created a dataset (called SellMng) inside i created a DataTable (called Products), I populate that DataTable with a procedure that executs : Select * from Product
Then in my form I bind this DataTable with a DataGridView (its work perfectly).
But I have to add (two or three columns) based on the Select, so I have something like this.
Name Description Complement
A blabla Blue Wood New
B ccccc YellowWood New
C yyyyy Red Maple New
And in the form the user can select the size of each column of the complement, so if the user select size 6:5:3 the DataGrid Should display
Name Description Complement Complement1 Complement2 Complement3
A blabla Blue Wood New Blue Wood New
B ccccc YellowWood New Yellow Wood New
C yyyyy Red Maple New Red Maple New
What I want to say is: The user can select the size of the complement and then the datagrid add columns based on the size selected by the user and the Content of the column Complement.
Im alredy did that, and It is working perfectly.
I did that like this
dgv.Columns.Add(_columnName, _displayName);
where _columnName is columnComplement1 columnComplement2....
and _displayName is Complement1 Complement2 Complement3.... (its inside a loop)
Then foreach Row in the datagridview I fill the columnComplement(x) based on the size defined by the user, something like this
foreach (DataGridRowView _row in dgv.Rows)
dgv.Rows.Current["columnComplement1"].Value = dgv.Rows.Current["columComplement"].Value.Substring(x,y);
Ok. everything is working perfectly
Now the problem: When I some column (if I click in a column Header my datagridview sort the Data base on this column) The column Complement1, Complement2, etc.... lost his value, the become blank column. Like this
(i Sorted by Name)
Name Description Complement Complement1 Complement2 Complement3
C yyyyy Red Maple New
B ccccc YellowWood New
A blabla Blue Wood New
The value of complement1, complment2 complement3, Just disapear.
What should I do ???
Thanks
Continue reading...