Windows Develop Bookmark and Share   
 index > Windows Forms Designer > make a row readonly when a checkboxcell is checked and wiseversa
 

make a row readonly when a checkboxcell is checked and wiseversa

Hi all

DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();
checkBoxColumn.Width = 20;
this.dgvallocation.Columns.Insert(0, checkBoxColumn);
dgvallocation.DataSource = newdt;

My datagridview have a checkbox column and datasource binded to it ,when i click the checkbox i should make the row readonly and when i uncheck i should make it readonly to false.How to achieve this

Regards

damodar

damu maddy  Friday, January 30, 2009 5:14 PM
You need to do it by adding your own code. The class being designed does not have a property for the runtime behavior you need.
MSMVP VC++
Sheng Jiang 蒋晟  Friday, January 30, 2009 7:32 PM
You need to do it by adding your own code. The class being designed does not have a property for the runtime behavior you need.
MSMVP VC++
Sheng Jiang 蒋晟  Friday, January 30, 2009 7:32 PM
Hi damu maddy,

As @Sheng Jiang said, there is no built-in property to support this behavior. But we can implement by our own code.

When you change a cell’s value, it cause CellValueChanged event. We can set ReadOnly property to a row, a column or a cell. Try something like the following:

private void Form1_Load(object sender, EventArgs e)

DataTable dt1 = new DataTable("dt1");

"tag");

for (int i = 0; i < 10; i++)

"aa");

DataGridViewCheckBoxColumn checkBoxColumn = new DataGridViewCheckBoxColumn();

this.dataGridView1.Columns.Insert(0, checkBoxColumn);

this.dataGridView1.CellValueChanged += new DataGridViewCellEventHandler(dataGridView1_CellValueChanged);

void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)

if (e.ColumnIndex == 0)

// if checked

if (dataGridView1.CurrentCell.Value.ToString() == "True")

// make the row readonly except the first cell(check box)

true;

false;

else // unchecked

false;

If you have any other questions, please feel free to ask.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Friday, February 06, 2009 2:38 AM

You can use google to search for other answers

Custom Search

More Threads

• Displaying different image size in a listview.
• Elapsed Time
• How to change the color of textbox after set enable to false?
• Resize a panel
• Visual Studio is not adding a .resx with a form...
• UserControl DataGridView ColumnDesigner
• Size of controls in design view
• groupbox heading text font changeable or not?
• Problem with Windows Forms Inheritance in designer
• new to XML ..Write XML How ?? [:(]