Problem with DataGrid_CellFormatting event to set default value
- by Royson
Hi,
I have created an applicationto display list of files. it also provide user interface for adding new column to a gridview.
DataGridViewTextBoxColumn txtBoxColumn = new DataGridViewTextBoxColumn();
txtBoxColumn.Name = columnName;
txtBoxColumn.HeaderText = columnName;
g_dataGridView.Columns.Add(txtBoxColumn);
User will create some custom type column therefore i am adding column directly to grid.
I am also able to set its default value before adding for this i am using
DataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (colIndexWithDefaultValue.Count > 0)
{
if (colIndexWithDefaultValue.Contains(e.ColumnIndex))
{
g_dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = colIndexWithDefaultValue[e.ColumnIndex];
}
}
}
where colIndexWithDefaultValue is list
of columns with its default value.
It is able to show newly created column with default value.
But values are getting set for currently visible rows. To set value for all rows i have to do scrolling.
So, how do i overcome this problem...