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

Need Help in applying color to selected row in a DBG

i am displaying rows into a DBG.and i placed a context menu strip control on it.
after displaying rows in a grid i am selecting a row and applying a color to that row by clicking on contextmenu strip button
but it is not applying that color

my code is
private void Form1_Load(object sender, EventArgs e)
{

string con = "data source=SERVER;uid=sa;pwd=safertek;database=master";
string cmd = " select * from emp";
SqlDataAdapter da = new SqlDataAdapter(cmd, con);
DataSet ds = new DataSet();
da.Fill(ds, "emp");
gridDataBoundGrid1.DataSource = ds.Tables[0];

this.gridDataBoundGrid1[1, 1].BackColor = Color.GreenYellow;
this.gridDataBoundGrid1[1, 1].TextColor = Color.RoyalBlue;
this.gridDataBoundGrid1[1, 1].CellType = "TextBox";

}

private void buttonAdv1_Click(object sender, EventArgs e)
{
Application.Exit();
}

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
int i = gridDataBoundGrid1.CurrentCell.RowIndex;
int c = gridDataBoundGrid1.CurrentCell.ColIndex;
this.gridDataBoundGrid1[i, c].BackColor = Color.GreenYellow;
}



3 Replies

SR Sri Rajan Syncfusion Team June 13, 2008 09:43 AM UTC

Hi Hari,

Thank you for your interest in Syncfusion products.

You need to handle QueryCellInfo event to change the back color of the selected cell. Here is the code.

//To Change the backcolor of selected cell.
void Model_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)
{
if ((e.RowIndex == i && i!=-1)&& (e.ColIndex == c && c!=-1))
{
e.Style.BackColor = Color.Red;
i = -1;
c = -1;
}
else
{
if(e.RowIndex>0 && e.ColIndex>0)
e.Style.BackColor = Color.White;
}
}

int i = -1, c = -1;
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
i = this.gridDataBoundGrid1.CurrentCell.RowIndex;
c = this.gridDataBoundGrid1.CurrentCell.ColIndex;
this.gridDataBoundGrid1.Focus();
}


Please let me know if this helps.

Best Regards,
Srirajan



AD Administrator Syncfusion Team June 14, 2008 06:31 AM UTC

ThankYou Srirajan

Can you plz provide any documentation regarding GridBoundDataGrid events like Model_QueryCellInfo,
PrepareViewStyleInfo,
CurrentCellAcceptedChanges..
thanks in advance




SR Sri Rajan Syncfusion Team June 16, 2008 06:40 AM UTC

Hi Hari,

Thank you for your continued interest in Syncfusion products.

Here is the documentation for the events of GridDataBoundGrid control.
http://www2.syncfusion.com/cref_63/cref_files/grid_win/html/5293b51c-7841-41b3-cffa-5b1322dda62a.htm#eventTableToggle

Please let me know if this helps.

Best Regards,
Srirajan.


Loader.
Live Chat Icon For mobile
Up arrow icon