5 Replies - 240 Views - Last Post: 13 February 2013 - 10:18 AM Rate Topic: -----

#1 varunit  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 03-September 09

dynamically adding text - 3 comboboxes, 1 textbox and a button

Posted 12 February 2013 - 09:41 PM

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?

Is This A Good Question/Topic? 0
  • +

Replies To: dynamically adding text - 3 comboboxes, 1 textbox and a button

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10180
  • View blog
  • Posts: 37,585
  • Joined: 27-December 08

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.
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3160
  • View blog
  • Posts: 9,532
  • Joined: 05-May 12

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


Was This Post Helpful? 1
  • +
  • -

#4 varunit  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 03-September 09

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
Was This Post Helpful? 0
  • +
  • -

#5 Michael26  Icon User is offline

  • Radar love
  • member icon

Reputation: 332
  • View blog
  • Posts: 1,419
  • Joined: 08-April 09

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.

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.
Was This Post Helpful? 0
  • +
  • -

#6 varunit  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 35
  • Joined: 03-September 09

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1