DataGridView Read Only Columns and Rows
The DataGridView control for displaying and editing tabular data. The ReadOnly property indicates whether the data displayed by the cell can be edited or not. You can set ReadOnly Property in three levels. You can make entire dataGridView or entire column or entire row as ReadOnly .
dataGridView.ReadOnly = true;
dataGridView.Rows[0].ReadOnly = true;
dataGridView.Columns[0].ReadOnly = true;
private void button1_Click(object sender, EventArgs e) { dataGridView1.ColumnCount = 3; dataGridView1.Columns[0].Name = "Product ID"; dataGridView1.Columns[1].Name = "Product Name"; dataGridView1.Columns[2].Name = "Product Price"; string[] row = new string[] { "1", "Product 1", "1000" }; dataGridView1.Rows.Add(row); row = new string[] { "2", "Product 2", "2000" }; dataGridView1.Rows.Add(row); row = new string[] { "3", "Product 3", "3000" }; dataGridView1.Rows.Add(row); row = new string[] { "4", "Product 4", "4000" }; dataGridView1.Rows.Add(row); dataGridView1.Rows[1].ReadOnly = true; }
0 comments:
Post a Comment