【发布时间】:2015-08-14 19:37:33
【问题描述】:
我在 datagridview 中遇到了一些奇怪的问题。我有带有 ComboBox Column 的 datagridview。我使用了 datagridviewv_EditingControlShowing 事件,然后使用了 GridCombo_SelectedIndexChanged 事件。第一次从 Combobox 中选择一些 Disply 成员时没有问题。但在那之后它的颜色更改为黑色和蓝色。所以显示成员不显示。请查看屏幕截图了解更多详细信息。
private void datagridview_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (e.Control is TextBox)
{
TextBox tb = e.Control as TextBox;
if (flgCellEdit == true)
{
tb.KeyPress += new KeyPressEventHandler(NumericValidation_KeyPress);
//tb.Leave += new EventHandler(GridTextBox_LeaveEvent);
}
else
{
tb.KeyPress += new KeyPressEventHandler(NumericValidationCancel_KeyPress);
}
}
if (e.Control is ComboBox)
{
ComboBox comboBox = e.Control as ComboBox;
switch ((sender as DataGridView).Name)
{
case "dgvIPO":
comboBox.SelectedIndexChanged += new EventHandler(GridCombo_SelectedIndexChanged);
break;
}
}
} private void GridCombo_SelectedIndexChanged(object sender, EventArgs e)
{
DataGridView dgv = (sender as DataGridViewComboBoxEditingControl).EditingControlDataGridView as DataGridView;
DataGridViewRow dgvr = dgv.Rows[(sender as DataGridViewComboBoxEditingControl).EditingControlRowIndex];
switch (dgv.Name)
{
case "dgvIPO":
if (dgvr.Cells[5].EditedFormattedValue.ToString() == "N" && dgvr.Cells[6].EditedFormattedValue.ToString() == "N" && dgvr.Cells[7].EditedFormattedValue.ToString() == "N" && dgvr.Cells[8].EditedFormattedValue.ToString() == "N" && dgvr.Cells[9].EditedFormattedValue.ToString() == "N")
{
dgvr.Cells[10].Value = "Complies";
}
else
{
dgvr.Cells[10].Value = "Non Complies";
}
txtAcceptedQtySt1.Text = dgvIPO.Rows.Cast<DataGridViewRow>().Where(r => r.Cells[10].EditedFormattedValue.ToString() == "Complies").Count().ToString();
break;
}
}`
【问题讨论】:
-
你能提供你用来显示这个
DataGridView的代码 -
Prdnya Bolli ...我不需要这个..我在问为什么组合框的颜色一直在改变..??
-
我也有同样的事情:使用 EditingControlShowing 事件来创建 SelectedIndexChangedEvent。仅查看 SelectedIndexChanged 事件处理程序中的 EditedFormattedValue 属性意味着当我在 DataGridView 上使用另一个 ComboBoxCell (同一行不同列或不同行任何列)时,下拉背景变为黑色。很奇怪。
标签: c# winforms datagridview datagridcomboboxcolumn