嗨程序员, 实际上我在DataGridvIew中有一个DataGridViewComboBoxCell,如果在触发CellContentClick事件时条件为真,我需要更改DataGridViewComboBox值。 我的代码就像这样:
private void gridviewholiday_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
int row = e.RowIndex;
int colo = e.ColumnIndex;
/*=============== To Show The Details =====================*/
if (e.ColumnIndex == 4)
{
if (Convert.ToBoolean(gridviewholiday.Rows[e.RowIndex].Cells[0].Value))
{
if (Type == "CUS")
{
Type = test.colType;
if (Type == "NO")
{
ComboBox combo = (ComboBox)sender;
combo.SelectedIndex = 0;
}
}
}
但是在将DataGridView转换为Combobox时会出错。
请帮帮我。
答案 0 :(得分:1)
你好朋友!
我得到了答案,我手动选择了DataGridviewComboBoxCell。
private void gridviewholiday_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
{
int row = e.RowIndex;
int colo = e.ColumnIndex;
/*=============== To Show The Details =====================*/
if (e.ColumnIndex == 4)
{
if (Convert.ToBoolean(gridviewholiday.Rows[e.RowIndex].Cells[0].Value))
{
if (Type == "CUS")
{
Type = test.colType;
if (Type == "NO")
{
/*===== set the selected value of comboboxCellItems ==========*/
gridviewholiday.Rows[e.RowIndex].Cells["colType"].Value="ALL"
}
}
}
最后我的问题解决了。