如何在datagridview中设置一行复选框值false

时间:2011-02-22 06:49:28

标签: c#

如何在datagridview中设置一行复选框值false

3 个答案:

答案 0 :(得分:1)

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

        }

试试这个

答案 1 :(得分:0)

//添加一个新列(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";

看来这在VisualStudio中会容易得多 - 也许? 以下是创建Combobox列的例程 - 与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; 
} 

如果userAddedRow标志设置为true,则取消设置标志; userAddedRow = false;并将id设置为0,因为从1开始从服务器自动增加了id: -

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

答案 2 :(得分:0)

您应该将其转换为datagridviewcheckbox并将其值设置为false