Index and Value do not match
Hello,
After I do column reorder and my updated value are not in correct cell.
I'm using like this. Below code it is showing the correct index but in end user UI , data are wrong.
What do I need to do more?.. Thanks in advance.
Column column = grid1.Headers[0][i];
String TempColName = column.Id;
if (TempColName == "-1")
return;
if (htData.ContainsKey(TempColName))
{
String Val = htData[TempColName].ToString();
if (Val != null && Val != "")
{
int columnVisibleIndex = column.VisibleIndex;
grid1.Rows[iRowIndex][columnVisibleIndex].Value = Val;
}
}
-
Hi,
The problem is that your data doesn't have string identifiers which can be used to display content in cells. I.e. your add data is like object[]. Therefore each value in the object[] can be accessed only by its index. When you reorder or filter columns, the grid can' detect which index should be used to get nested value. Our recomendation is to use objects of custom classes:class MyClass
{
decimal Name {get; set;}
decimal Price {get; set;}
}
grid.Headers.Add(new Header());
grid.Headers[0].Add(new Column("Name"));
grid.Headers[0].Add(new Column("Price"));
grid.Rows.Add(new MyClass());
This is more performant, takes less memory, makes the code more clean, and brings separation business level from its presentation.
Regards,
Dapfor0
Please sign in to leave a comment.
Comments
1 comment