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);
}
}
Loading

Christofel Hakim81 reputationPosted May 25, 2010, 12:26 AM EDT
Before your select the new item in combo box, you need to add the new item first into that combo box items.
comboBox1.Items.Add(TheOriginalValue); // add the item first
comboBox1.SelectedValue = TheOriginalvalue // then select it
CrishRank #1,487 · 1.1K reputationPosted May 24, 2010, 9:15 PM EDT
try below code
comboBox1.Selectedvalue = TheOriginalValue
thanks
GustavoRank #1,990 · 732 reputationPosted May 25, 2010, 12:00 AM EDT
Thanks, but it does not work. I have to somehow define the ComboBox that its at.
Loading the TextBox with: TheControlEvent.Text = TheOriginalValue; Works.
But, loading the ComboBox doesnt.
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 "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 "Column"].Value.ToString(); TheOriginalValue = dataGridViewRecord.Rows[TheRow].Cells["TheOriginal"].Value.ToString(); if (TheEventName.Substring(8) == TheColumnValue) { TheControlEvent.Text = TheOriginalValue; // This does not work // // NEEDS WORK TO SHOW: Selected Item // break; } } break; default: break; } TheControlEvent = this.GetNextControl(TheControlEvent, true); } }GustavoRank #1,990 · 732 reputationPosted May 25, 2010, 12:31 AM EDT
((ComboBox)TheControlEvent).Items.Add(TheOriginalValue);
((ComboBox)TheControlEvent).SelectedValue = TheOriginalValue;
It does load it, but it does not show it on the ComboBox. I have to click and select it to show it for the first time.
Christofel Hakim81 reputationPosted May 25, 2010, 1:18 AM EDT
((ComboBox)TheControlEvent).SelectedItem.Text = TheOriginalValue;
GustavoRank #1,990 · 732 reputationPosted May 25, 2010, 1:22 AM EDT
With some things you said in the other posts, I have figured it out. Thanks.
I also had to do a change in my other routine to full make it work.
Thanks for leading me the correct direction.
((ComboBox)TheControlEvent).Items.Add(TheOriginalValue);
((ComboBox)TheControlEvent).Text = TheOriginalValue;
((ComboBox)TheControlEvent).SelectedIndex = 0;
I guess I had to do the ((ComboBox)TheControlEvent).SelectedIndex = 0; so it would show it in the Form. Then I had to use the ((ComboBox)TheControlEvent).Text in my other routine after I load all the selections.
Thanks