I have 3 combo boxes and one text box and a button. Each combobox contains an item (custom). When this item is selected, the focus has to bemoved to textbox and when ADD button is clicked, the text typed in textbox has to be added as an item to the combobox from which selections has made. I'm confused with how to identify which combo box has sent the "custom" item adding event and how to add the new item to that combobox. Could anyone help me in doing this?
5 Replies - 125 Views - Last Post: 13 February 2013 - 10:18 AM
#1
dynamically adding text - 3 comboboxes, 1 textbox and a button
Posted 12 February 2013 - 09:41 PM
Replies To: dynamically adding text - 3 comboboxes, 1 textbox and a button
#2
Re: dynamically adding text - 3 comboboxes, 1 textbox and a button
Posted 12 February 2013 - 09:46 PM
Moved to C#. Please don't post help questions in the Advanced Discussion forum.
#3
Re: dynamically adding text - 3 comboboxes, 1 textbox and a button
Posted 12 February 2013 - 10:07 PM
Seems like a simple enough problem. When you get the selected item change event for the comboboxes, you check to see if the selected item is custom. If it is, you set a member variable named lastCustom to the current combobox, and then set the focus on the textbox. Then when the click event is fired on the button, you add the value in the textbox to the lastCustom.
In pseudo code:
In pseudo code:
class MyForm
{
ComboBox _lastCustom;
:
void ComboBox_SelectionchangeCommitted(object sender, EventArgs e)
{
ComboBox thisComboBox = (ComboBox) sender;
if (thisComboBox.SelectedItem matches "custom")
{
_lastCustom = thisComboBox;
_textBox.Focus();
}
}
void AddButton_Click(object sender, EventArgs e)
{
_lastCustom.Items.Add(_textBox.Text);
}
}
#4
Re: dynamically adding text - 3 comboboxes, 1 textbox and a button
Posted 13 February 2013 - 01:27 AM
@Skydiver, Thanks for the response. I forgot to mention that I'm using TextChanged event to handle the User Selection. Anyways, I'll try this snippet with my TextChanged event and will post the results. Thanks
#5
Re: dynamically adding text - 3 comboboxes, 1 textbox and a button
Posted 13 February 2013 - 02:00 AM
Skydiver is right, when something happens (the item is selected in combo-box) a corresponding event has to occur, so i don't think TextChanged event will work for item selected in combo-box.
In Skydiver's pseudo code this is
you'll see why if you try to debug your code.
Quote
I'm confused with how to identify which combo box has sent the "custom" item adding event and how to add the new item to that combobox
In Skydiver's pseudo code this is
ComboBox thisComboBox = (ComboBox) sender;
you'll see why if you try to debug your code.
#6
Re: dynamically adding text - 3 comboboxes, 1 textbox and a button
Posted 13 February 2013 - 10:18 AM
Thank you skydiver. I'm able to add items to list without any issues.
Thank you Michael26 for your reply.
Thank you Michael26 for your reply.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|