Click here to Skip to main content
15,923,087 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

GridView's RowDataBound equivalent event in Windows DataGridView..
Posted
Updated 12-Mar-19 8:59am

C#
 private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
//bala bala
        }
 
Share this answer
 
Refer -
1. gridview rowdatabound event in winforms?[^]
Quote:
The DataGridView doesn't have the same event handling as in ASP.NET.

What you could do is handle RowsAdded event, but note that more than one row can be added when this event fires. An example:

C#
private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
    for (int i = e.RowIndex; i < e.RowCount + e.RowIndex; i++)
    {
        Console.WriteLine("Row " + i.ToString() + " added");
    }
}

Also, this event is a bit 'buggy' - at the moment when it's databound it may fire more than once for each row, but afterwards it behaves correctly - when you add a new row to data source, it's fired only once.

But, I should probably mention (even if that's not your original question), that if you used this event in ASPX to handle output formatting, than here an equivalent would actually be CellFormatting event - this event is called whenever the cells needs to display it's value.

2. RowDataBound for DatagridView Windows Forms[^]
 
Share this answer
 
v2
I found that if the cell was not visible, ie off the right-hand edge of the screen, the row was not painted.

I've instead linked the code to RowPrePaint event.

private void dataGridView1_RowPrePaint ( object sender, DataGridViewRowPrePaintEventArgs e )
{
  if ( (bool)dataGridView1.Rows[e.RowIndex].Cells[userColumn].Value == true )
  {
    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.MistyRose;
  }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900