We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Grid List control

I am using 2 gridlist controls in my project. There is a requirement that as soon as I select a code in the first gridlist control, it should be added to the first position in the second gridlist and the color of text in that first/top row should be different from the default color of other rows.
Thus, if I add one more record to the second gridlist control, this particular record should be shown in different color and the rest of the records should be shown in defualt color.
Is this possible in GridList control and if so then how?

SA


1 Reply

HA haneefm Syncfusion Team December 4, 2007 09:23 PM UTC

Hi,

You can acheive this by handling the PrepareViewStyleInfo event of the gridcontrol.

The idea is to have a hashtable and in that hastable, set the ID of the datarow in the SelectedValueChanged event and check that ID in PrepareViewStyleInfo event of another gridlistcontrol to provide the color of the row. Below are codes that shows this task.

this.gridListControl2.Grid.PrepareViewStyleInfo += new GridPrepareViewStyleInfoEventHandler(Grid_PrepareViewStyleInfo);

void gridListControl1_SelectedValueChanged(object sender, EventArgs e)
{
GridListControl ListControl = sender as GridListControl;
DataRowView dr = ListControl.SelectedValue as DataRowView;

if ( !prevHashtable.Contains(dr[0]))
{
prevHashtable.Add(dr[0]);
DataTable dt = this.gridListControl2.DataSource as DataTable;
DataRow drow = dt.NewRow();
drow.ItemArray = dr.Row.ItemArray;
dt.Rows.InsertAt(drow, 0);
this.gridListControl2.Grid.ResetVolatileData();
this.gridListControl2.Refresh();
}
}

void Grid_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
if (e.RowIndex > 0 && e.ColIndex > 0)
{
GridControl grid = sender as GridControl;
if (prevHashtable.Contains(grid.Model[e.RowIndex, 1].CellValue))
{
e.Style.BackColor = Color.Coral;
}

}
}

Please refer to the attached sample for implementation.
GridListControl.zip

Best regards,
Haneef


Loader.
Live Chat Icon For mobile
Up arrow icon