mthakershi
Programmer
Hi all,
It would be great if some can help me solve this mystery.
I have a DataGridView in C# windows application which uses .NET 2.0. The gridview has a combobox cell, two textbox cells and 2 hidden cells. I have written EditingControlShowing event handler to add a SelectedIndexChanged event handler to the gridview combobox. The problem is: after one or two clicks, all cells get black background when focused. All combobox items when dropped down become black. When I comment out the event, this doesn't happen.
Here is the code:
private void dgVendorsEditVendors_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();
//if the editing control is vendor name cell
//then add a selectedindex changed event to it
//so that when it changes, we can simultaneously change
//vendor id and retail per values
Control pObjCtrl = dgVendorsEditVendors.EditingControl;
if (pObjCtrl != null)
{
//pObjCtrl.BackColor = Color.FromKnownColor(KnownColor.Window);
//pObjCtrl.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
if (pObjCtrl.GetType().Name.Trim().ToUpper().Equals("DATAGRIDVIEWCOMBOBOXEDITINGCONTROL"))
{
DataGridViewComboBoxEditingControl pObjCmb = (DataGridViewComboBoxEditingControl)pObjCtrl;
pObjCmb.SelectedIndexChanged -= new EventHandler(dgVendorsEditVendors_VndName_SelectedIndexChanged);
pObjCmb.SelectedIndexChanged += new EventHandler(dgVendorsEditVendors_VndName_SelectedIndexChanged);
pObjCmb = null;
}
pObjCtrl = null;
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message.ToString());
CSCommon.gfpErrorMessage(this, ex);
}
finally
{
this.Cursor = Cursors.Default;
}
}
private void dgVendorsEditVendors_VndName_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();
//this will be called when selectedindex changes in first column of the grid
Control pObjCtrl = dgVendorsEditVendors.EditingControl;
if (pObjCtrl != null)
{
if (pObjCtrl.GetType().Name.Trim().ToUpper().Equals("DATAGRIDVIEWCOMBOBOXEDITINGCONTROL"))
{
DataGridViewComboBoxEditingControl pObjCmb = (DataGridViewComboBoxEditingControl)pObjCtrl;
//based on the new selectedindex, assign retail percentage and vndid to this row
dgVendorsEditVendors["colVendorsEditVndID", dgVendorsEditVendors.CurrentCell.RowIndex].Value =
cmbHidVendorsEntryVendors.Items[pObjCmb.SelectedIndex].ToString().Trim();
dgVendorsEditVendors["colVendorsEditVndPer", dgVendorsEditVendors.CurrentCell.RowIndex].Value =
cmbHidVendorsEntryPer.Items[pObjCmb.SelectedIndex].ToString().Trim();
pObjCmb = null;
}
pObjCtrl = null;
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message.ToString());
CSCommon.gfpErrorMessage(this, ex);
}
finally
{
this.Cursor = Cursors.Default;
}
}
Hope to hear from someone soon.
Thanks a lot.
Malay
It would be great if some can help me solve this mystery.
I have a DataGridView in C# windows application which uses .NET 2.0. The gridview has a combobox cell, two textbox cells and 2 hidden cells. I have written EditingControlShowing event handler to add a SelectedIndexChanged event handler to the gridview combobox. The problem is: after one or two clicks, all cells get black background when focused. All combobox items when dropped down become black. When I comment out the event, this doesn't happen.
Here is the code:
private void dgVendorsEditVendors_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();
//if the editing control is vendor name cell
//then add a selectedindex changed event to it
//so that when it changes, we can simultaneously change
//vendor id and retail per values
Control pObjCtrl = dgVendorsEditVendors.EditingControl;
if (pObjCtrl != null)
{
//pObjCtrl.BackColor = Color.FromKnownColor(KnownColor.Window);
//pObjCtrl.ForeColor = Color.FromKnownColor(KnownColor.ControlText);
if (pObjCtrl.GetType().Name.Trim().ToUpper().Equals("DATAGRIDVIEWCOMBOBOXEDITINGCONTROL"))
{
DataGridViewComboBoxEditingControl pObjCmb = (DataGridViewComboBoxEditingControl)pObjCtrl;
pObjCmb.SelectedIndexChanged -= new EventHandler(dgVendorsEditVendors_VndName_SelectedIndexChanged);
pObjCmb.SelectedIndexChanged += new EventHandler(dgVendorsEditVendors_VndName_SelectedIndexChanged);
pObjCmb = null;
}
pObjCtrl = null;
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message.ToString());
CSCommon.gfpErrorMessage(this, ex);
}
finally
{
this.Cursor = Cursors.Default;
}
}
private void dgVendorsEditVendors_VndName_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
Application.DoEvents();
//this will be called when selectedindex changes in first column of the grid
Control pObjCtrl = dgVendorsEditVendors.EditingControl;
if (pObjCtrl != null)
{
if (pObjCtrl.GetType().Name.Trim().ToUpper().Equals("DATAGRIDVIEWCOMBOBOXEDITINGCONTROL"))
{
DataGridViewComboBoxEditingControl pObjCmb = (DataGridViewComboBoxEditingControl)pObjCtrl;
//based on the new selectedindex, assign retail percentage and vndid to this row
dgVendorsEditVendors["colVendorsEditVndID", dgVendorsEditVendors.CurrentCell.RowIndex].Value =
cmbHidVendorsEntryVendors.Items[pObjCmb.SelectedIndex].ToString().Trim();
dgVendorsEditVendors["colVendorsEditVndPer", dgVendorsEditVendors.CurrentCell.RowIndex].Value =
cmbHidVendorsEntryPer.Items[pObjCmb.SelectedIndex].ToString().Trim();
pObjCmb = null;
}
pObjCtrl = null;
}
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message.ToString());
CSCommon.gfpErrorMessage(this, ex);
}
finally
{
this.Cursor = Cursors.Default;
}
}
Hope to hear from someone soon.
Thanks a lot.
Malay