Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGridView EditingControlShowing Cells blackout

Status
Not open for further replies.

mthakershi

Programmer
Aug 24, 2001
79
US
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
 
Hi all,

As of now my problem is solved but I don't understand how. I removed Application.DoEvents() from both procedures and it doesn't happen now.

I guess event Microsoft doesn't know what is happening inside.

Malay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top