Hi ,
I have a comboBox that has three options i.e TextBox , ComboxBox , UltraComboEditor ( with check boxes). Depending on what the user clicks , that control should be displayed ontop of a Panel in a Table Layout Panel. I am achieving this using if else and setting Visible property to true for one of them and false for the other two.
The text box and combobox get displayed when i choose the respective option but UltraComboEditor doesnt get displayed . Initiailly I keep all of their visibily to false . Then I go changing based on user selection.
My problem is that my UltraComboEditor never seems to be displayed. Heres some code :
private void Form1_Load(object sender, EventArgs e) {
this.ultraComboEditor1.CheckedListSettings.CheckBoxStyle = Infragistics.Win.CheckStyle.CheckBox; this.ultraComboEditor1.CheckedListSettings.CheckBoxAlignment = ContentAlignment.MiddleLeft;
}
private void comboBox3_SelectionChangeCommitted(object sender, EventArgs e) { ReplaceComponent((ComboBox) sender, comboBox8, textBox3,ultraComboEditor3);
private void ReplaceComponent(ComboBox sender,ComboBox c,TextBox t,UltraComboEditor u) { if (sender.SelectedItem.ToString() == "ComboBox") { c.Items.Clear(); c.Items.Add(""); c.Items.Add("ASA"); c.Visible = true; t.Visible = false; u.Visible = false; } else if (sender.SelectedItem.ToString() == "UltraComboEditor") { u.Items.Clear(); u.Items.Add("Black Oil"); u.Items.Add("Dry Gas"); u.Items.Add("Gas Cond"); u.Items.Add("Heavy Oil"); u.Items.Add("Volatile Oil");
u.Visible = true;
t.Visible = false; receiver.Visible = false; } else if (sender.SelectedItem.ToString() == "TextBox") {
u.Visible = false;
t.Visible = true;receiver.Visible = false;
Only other way i can do this is by passing the panel and clearing all contorls and adding the one I want .
Hi Prasaanth,
Thank you for posting in our forums.
I have created a small sample based on the provided code and I tested the described scenario. The UltraComboEditor (as any other control) is shown when its Visible property is set to true. Is the control added to the Controls collection of the form? What is the “receiver” control in your source code? Why aren’t you setting the Visible property of the ComboBox to false when you select the UltraComboEditor or the TextBox? The ComboBox may be hiding the UltraComboEditor.
I have attached the sample I used to test it. Please modify it so that it reproduces your issue or provide me with your own. I will be glad to research this issue further after I have receive the modified sample.
Thank you for your collaboration.
I am looking forward to hearing from you.
Hi Mike ,
Thank you for your repsonse.
The first post code had a typo. I had renamed my Combobox from receiver to c for your convenience but forgot to modify it it the later parts of the code. Sorry for the mistake i made.
This is the code I ran which DIDN't work for me :
private void ReplaceTextBoxWithDropDown(ComboBox sender,ComboBox c,TextBox t,UltraComboEditor u) {
if (sender.SelectedItem.ToString() == "Combobox") { c.Items.Clear(); c.Items.Add(""); c.Items.Add("ASA"); c.Items.Add("CHA"); c.Items.Add("EAF"); c.Items.Add("MCA"); c.Items.Add("MEA"); c.Items.Add("NAM"); c.Items.Add("RCA"); c.Items.Add("SAM"); t.Visible = false; u.Visible = false; c.Visible = true; } else if (sender.SelectedItem.ToString() == "UltracomboEditor") { u.Items.Clear(); u.Items.Add("Black Oil"); u.Items.Add("Dry Gas"); u.Items.Add("Gas Cond"); u.Items.Add("Heavy Oil"); u.Items.Add("Volatile Oil");
t.Visible = false; u.Visible = true; c.Visible = false; } else if (sender.SelectedItem.ToString() == "TextBox") {t.Visible = true;u.Visible = false;c.Visible = false;
The undelrying container for all three controls is a Panel say PanelX. normal windows Panel. There is panel within a Table Layout Panel cell where i have to switch between the above three components based on what the user selects elsewhere.
What I feel is that textbox and combobox display alright when i choose their options because I have dragged them into the PanelX in the designer . So they sit in it. UltraComboeditor I am not able to drag and place it such inside PanelX. Could this be the issue ?
In the example you attached , it runs because there is no container panel attached to any of the comoponents.
This is the code that did work for me.
// 4th parameter is PanelX effectively
private void ReplaceTextBoxWithDropDown(ComboBox sender,ComboBox c,TextBox t,UltraComboEditor u,Panel panel){
if (sender.SelectedItem.ToString() == "Combobox"){c.Items.Clear();c.Items.Add("");c.Items.Add("ASA");c.Items.Add("CHA");c.Items.Add("EAF");c.Items.Add("MCA");c.Items.Add("MEA");c.Items.Add("NAM");c.Items.Add("RCA");c.Items.Add("SAM");
panel.Controls.Clear();panel.Controls.Add(c); panel.Dock = DockStyle.Fill;
}else if (sender.SelectedItem.ToString() == "UltracomboEditor"){u.Items.Clear();u.Items.Add("Black Oil");u.Items.Add("Dry Gas");u.Items.Add("Gas Cond");u.Items.Add("Heavy Oil");u.Items.Add("Volatile Oil");
panel.Controls.Clear();panel.Controls.Add(u); panel.Dock = DockStyle.Fill;
}else if (sender.SelectedItem.ToString() == "TextBox"){
panel.Controls.Clear();panel.Controls.Add(t);panel.Dock = DockStyle.Fill;
However am not comfortable with this and it feels unwieldy to add and remove controls.
Sorry ,
I wished to say Hi Dimitar. :)
also i would like to know how to get all the checked items in an ultracomboeditor as a list of strings.
right now am iterating and adding the items cast to list. is there a better way
Hello Prasaanth,
I am just checking about the progress of this issue. Let me know if you need my further assistance on this issue.
Thank you for using Infragistics Components.