kumarsram
kumarsram

Reputation: 611

how to set checkbox value false in datagridview one row

how to set checkbox value false in datagridview one row

Upvotes: 1

Views: 1801

Answers (3)

Even
Even

Reputation: 411

You should convert it into a datagridviewcheckbox and set its value to false.

Upvotes: 0

Even
Even

Reputation: 411

 private void dgvTodaysPlan_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            if (dgvTodaysPlan.CurrentCell is System.Windows.Forms.DataGridViewCheckBoxCell)
            {
                dgvTodaysPlan.CommitEdit(DataGridViewDataErrorContexts.Commit);
            }

        }

try this

Upvotes: 1

Yoko Zunna
Yoko Zunna

Reputation: 1824

// Add a new Column (ComboBox)

DataGridViewComboBoxColumn colForeign = new DataGridViewComboBoxColumn(); 
colForeign = MyDB.CreateComboBoxColumn("SELECT subjno,subject FROM subject", "ComboForeign", "subject", "subjno"); 
colForeign.HeaderText = "Subject"; 
colForeign.Width = 120; 
colForeign.DisplayStyle = 0; 
this.dataGridView2.Columns.Insert(3, colForeign) 
Use DataPropertyName to get the selected key column as in :- 
this.dataGridView2.Columns[3].DataPropertyName = "subjno";

It appears that this would be much easier in VisualStudio - maybe?? And here is the routine to Create the Combobox Column - very messy compared with Delphi :-

public DataGridViewComboBoxColumn CreateComboBoxColumn(string strSQLSelect, string strColName, string strDisplay, string strValue) 
{ 
// Returns the DataGridViewComboBoxColumn to be inserted 
DataGridViewComboBoxColumn colComboColumn = new DataGridViewComboBoxColumn(); 
DataTable dtbElements = new DataTable(); 
MySqlDataAdapter dbaElements = new MySqlDataAdapter(strSQLSelect, conn); 
// Set some parameters for the ComboBoxColumn 
colComboColumn.Name = strColName; 
colComboColumn.DisplayMember = strDisplay; 
colComboColumn.ValueMember = strValue; 
// Add the Elements 
dbaElements.Fill(dtbElements); 
colComboColumn.DataSource = dtbElements; 
// Return the column 
return colComboColumn; 
} 

If the userAddedRow flag is set to true, unset the flag; userAddedRow = false; and set id to 0, valid because autoincremented id's from server starting from 1 :-

dataGridView1["bookno", e.RowIndex].Value = 0;

Upvotes: 0

Related Questions