Windows Develop Bookmark and Share   
 index > Windows Forms General > Combobox dynamic text update issue on SelectedIndexChanged event handler
 

Combobox dynamic text update issue on SelectedIndexChanged event handler

Background:
I am trying to implement a mpp (ms project) style combobox, in which you can select from the list and then enter a comma & append to the selected text the next selected item from the list. The combobox should also be editable.
For example if the combobox has REG1, REG2, REG3, REG4 as list items, then the user should be able to select REG1,REG2 from the available list and the editable section of combobox should display REG1,REG2. The user should type the comma from the keyboard.

Issue:
The issue is that when I update the combobox1.text = "any text" on SelectedIndexChanged event handler, the previous value dissappears from the editable portion of combobox text. I can see the actual value that I have updated, only once I click on any other control on the form. I have been trying to do this with code but not have been successful so far.

Code:
public partial class sample1 : Form
{
private String combo2Value;
public sample1()
{
InitializeComponent();
}
private void sample1_Load(object sender, EventArgs e)
{
this.comboBox2.Items.Clear();
object[] items = { "REG1", "REG2", "REG3", "REG4", "REG5", "REG6" };
this.comboBox2.Items.AddRange(items);

combo2Value = "";
}
private void buttonOk_Click(object sender, EventArgs e)
{
MessageBox.Show(comboBox1.Text);
MessageBox.Show(comboBox2.Text);
comboBox2.Text = combo2Value;
MessageBox.Show(comboBox2.Text);
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
combo2Value += comboBox2.Text;
//MessageBox.Show("SelIndexChanged " + comboBox2.Text + " combo2Value=" + combo2Value);
comboBox2.Text = combo2Value;
label15.Focus();
}
void comboBox2_DropDownClosed(object sender, System.EventArgs e)
{
combo2Value = comboBox2.Text;
}

private void comboBox2_Leave(object sender, EventArgs e)
{
comboBox2.Text = combo2Value;
}

private void label15_GotFocus(object sender, EventArgs e)
{
//comboBox2.Text = combo2Value;
this.comboBox2.Focus();
}
}
}
  • Moved byOmegaManMVPTuesday, June 02, 2009 6:10 PM (From:Visual C# General)
  •  
svirdi  Tuesday, June 02, 2009 5:59 AM
svirdi,
For these functionality you need to develop your own control.

By using popup control,TextBox , button (which show down arrow) and checkedlistbox(list out items) can create such control.

Refer followinglink forPopupControl
http://www.codeproject.com/KB/miscctrl/simplepopup.aspx

Hopethis will solve your problem.


NareshG  Wednesday, June 03, 2009 6:27 AM

Hi svirdi,

Based on my understanding, you need a new control which is similar to ComboBox, but the control supports multi selection.

I found a project including some rich list controls by this link:

http://www.codeguru.com/csharp/csharp/cs_controls/treeview/article.php/c15373/ .

I think the EXTCombo control in this project can meet your needs.

Let me know if this helps.

Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, June 05, 2009 2:50 AM
Just reading the background, I'm wondering if something like a ListBox wouldn't be more suitable for your needs? You can set the SelectionMode property so your user can select multiple items. Then there wouldn't be any need for using the ComboBox to select one item, then type a comma and then select another item.
nmadd  Tuesday, June 02, 2009 5:09 PM
True, however I would also like to give user the choice to type an additional item after the comma.
For example: From the above sample from the original post, I can select REG1, REG6 & also type REG9. This would make my final text as: "REG1,REG6,REG9"
svirdi  Wednesday, June 03, 2009 6:00 AM
I agree with Nmadd, the user might be confused by they way you are using the combbox. Cant you use a listbox with a text box to add an option to it?


Ganesh Ranganathan
[Please mark the post as answer if you find it helpful]
Ganesh Ranganathan - Bangalore, India  Wednesday, June 03, 2009 6:08 AM
svirdi,
For these functionality you need to develop your own control.

By using popup control,TextBox , button (which show down arrow) and checkedlistbox(list out items) can create such control.

Refer followinglink forPopupControl
http://www.codeproject.com/KB/miscctrl/simplepopup.aspx

Hopethis will solve your problem.


NareshG  Wednesday, June 03, 2009 6:27 AM

Hi svirdi,

Based on my understanding, you need a new control which is similar to ComboBox, but the control supports multi selection.

I found a project including some rich list controls by this link:

http://www.codeguru.com/csharp/csharp/cs_controls/treeview/article.php/c15373/ .

I think the EXTCombo control in this project can meet your needs.

Let me know if this helps.

Aland Li


Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
Aland Li  Friday, June 05, 2009 2:50 AM

You can use google to search for other answers

Custom Search

More Threads

• Setting header style of columns in datagrid
• how to execute a button_click event from a different form
• .resx in c#
• AIM Like Button Scroll Panel Creation
• Design guidelines C# windows forms
• Sharing images Resources from multiple projects in a solution
• how to add value and string to listbox
• How can I catch the event that occur before a item is selected in System.Windows.Forms.ListBox control?
• Multiline Textbox scrolling
• Menu.MergeMenu leaks user objects