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 HakimPosted May 25, 2010, 4:26 AM
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
GustavoPosted May 25, 2010, 5:22 AM
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
Christofel HakimPosted May 25, 2010, 5:18 AM
((ComboBox)TheControlEvent).SelectedItem.Text = TheOriginalValue;
GustavoPosted May 25, 2010, 4:31 AM
((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.
GustavoPosted May 25, 2010, 4:00 AM
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.
CrishPosted May 25, 2010, 1:15 AM
try below code
comboBox1.Selectedvalue = TheOriginalValue
thanks