Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

datagridview editing won't work?

$
0
0

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

?





Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>