Datagrid and Dataview

djpaz25

Newcomer
Joined
Nov 12, 2003
Messages
12
I originally had a datagrid bound to a dataset. After loading the dataset, I would loop through it and make changes to the datagrid background colors based on values in the dataset. The code was something like:

if myDataset.myDataTable(i).STATUS = "C" then
myDatagrid.items(i).cells(1).BackColor = Color.Red
end if

That worked fine. I now have to added sorting capability. I've bound the datagrid to a dataview so that I can set the dataview.sort property. The problem now is that when I do a datagrid.databind, I loose the formatting of the datagrid. It does do the sorting though.

Any ideas on how I can do both the sorting and make changes to individual cell appearances?
 
Checking Value of Datagrid Cells

djpaz25 said:
I originally had a datagrid bound to a dataset. After loading the dataset, I would loop through it and make changes to the datagrid background colors based on values in the dataset. The code was something like:

if myDataset.myDataTable(i).STATUS = "C" then
myDatagrid.items(i).cells(1).BackColor = Color.Red
end if

That worked fine. I now have to added sorting capability. I've bound the datagrid to a dataview so that I can set the dataview.sort property. The problem now is that when I do a datagrid.databind, I loose the formatting of the datagrid. It does do the sorting though.

Any ideas on how I can do both the sorting and make changes to individual cell appearances?


OK, it appears that the datagrid.databind resets the format on the datagrid. I can actually live with that if I databind (sort) first and then make changes to cell appearances in the datagrid.

My new problem is that I can't set a cell's color based on the datatable's value any more because the sort changes the relationship between the grid and the dataset. After the sort, the second "row" of the dataset isn't necessarily displayed in the second row of the datagrid.

Instead of checking the value of myDataset.myDataTable(i).STATUS , I thought I could check the value of myDatagrid.items(i).cells(1).text (The STATUS value is stored in the 1st column.) However, myDatagrid.items(i).cells(1).text always seems to be Nothing, even after I do DataBind. I can do myDatagrid.items(i).cells(1).text = "Something", and it will display "Something". However, I can't seem to check the value.

Thanks for any help.
 
Make sure that the first time you bind in your load event that you check for Not IsPostBack
Also, Do your formatting and colorizing in the ItemDataBound Event
 
Back
Top