Hi

i have a databounded datagridview and i want to add row number programmatically to it

here is my code:

DataGridViewColumn _c = new DataGridViewColumn();
DataGridViewCell cell = new DataGridViewTextBoxCell(); 

_c.CellTemplate = cell;  
_c.HeaderText = "ID";  
_c.Name = "Num";     
_c.DataPropertyName = "Num"; 
_c.ReadOnly = false;  
_c.Visible = true; 
dgv.Columns.Insert(0, _c);

the code above will add a column name 'ID' to mydatagridview

i tried to fill those cells with these codes but non of them works :'(

dgv.Rows[0].Cells["Num"].Value = (1).ToString();


dgv[0, 0].Value = "1";


foreach (DataGridViewRow row in dgv.Rows)
{                    
   row.Cells["Num"].Value = (row.Index + 1).ToString(); 
}

thanks

?

i solved it with "VirtualMode=False".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.