Problem with DataGrid_CellFormatting event to set default value
        Posted  
        
            by Royson
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Royson
        
        
        
        Published on 2010-05-18T08:05:22Z
        Indexed on 
            2010/05/18
            8:11 UTC
        
        
        Read the original article
        Hit count: 236
        
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...
© Stack Overflow or respective owner