开发者

how to set checkbox value false in datagridview one row

how to set checkbox value false in datagridview 开发者_StackOverflow中文版one row


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

        }

try this


// 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;


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜