Gustavo

Gustavo

  • NA
  • 1.3k
  • 455.1k

How Do I: Show the Selected Item on a ComboBox in my Sample?

May 24 2010 4:44 PM

Hello:
 
Below is my code. I do load the new value into the ComboBox, but I dont know how to have it show on the Form. The values that I load in the textBox is fine, but the ComboBox does not show what is loaded. Can someone tell me what I need to do on the line: //comboBox1.SelectedItem = TheOriginalValue; ?
 
private void textBox_ID_Validated(object sender, EventArgs e)
{
Control TheControlEvent = this.GetNextControl(null, true);
while (TheControlEvent != null)
{
TheEventType = TheControlEvent.GetType().Name;
TheEventName = TheControlEvent.Name;
TheEventValue = TheControlEvent.Text;
switch (TheEventType)
{
case "TextBox":
for (TheRow = 0; TheRow < dataGridViewRecord.Rows.Count - 1; TheRow++)
{
TheColumnValue = dataGridViewRecord.Rows[TheRow].Cells[
"Column"].Value.ToString();
TheOriginalValue = dataGridViewRecord.Rows[TheRow].Cells[
"TheOriginal"].Value.ToString();
if (TheEventName.Substring(7) == TheColumnValue)
{
TheControlEvent.Text = TheOriginalValue;
break;
}
}
break;
case "ComboBox":
for (TheRow = 0; TheRow < dataGridViewRecord.Rows.Count - 1; TheRow++)
{
TheColumnValue = dataGridViewRecord.Rows[TheRow].Cells[
"Column"].Value.ToString();
TheOriginalValue = dataGridViewRecord.Rows[TheRow].Cells[
"TheOriginal"].Value.ToString();
if (TheEventName.Substring(8) == TheColumnValue)
{
TheControlEvent.Text = TheOriginalValue;
//TheControlEvent.Refresh();
//comboBox1.SelectedItem = TheOriginalValue;
// NEEDS WORK TO SHOW: SelectedItem
break;
}
}
break;
default:
break;
}
TheControlEvent =
this.GetNextControl(TheControlEvent, true);
}
}

Answers (6)