Microsoft Visual C# ComboBox/Listbox - c#

Is it possible to have my comboBox, numericUpDown, and ListBox connected together?
I want to make the numericUpDown to be the limit of the choices that you could made taht will be displayed in the listbox. For example:
If numericUpDown == 2 then,
comboBox == 5 choices. You Can Choose 2. Your first choice shouldn't be included in your second lookthrough of the combobox. then,
listbox == 2. (The listbox should only contain data. Depending on the value of the numericUpDown) So if the user choose again in the combobox the datas in the list box wouldn't be affected.
How might I implement this?

C# has most of the useful controls but sometimes what you need is not there.
You can always make your own controls or just add a little coding to get what you want.
Nothing Is Impossible.
Here is a simple way to make your own Control and then use it in your program.
http://www.codeproject.com/KB/miscctrl/first_control.aspx

Related

visual studio 2015, how hot enable combo box for different choices? in C#

i'm learning how to use C# and visual studio, and what i am trying to do is that
for example
the question
i have coxcomb 1:
when user choose the first option, i want to display to him some specific buttons and 2 combo-boxes.
but when he choose option 2, i want to display different options and 5 combo-boxes, its like i want to have a side page that can change depends on the user choices, so can anyone help me with that?
should i user the property grid?
this is what i have do far
You can check what the user chose with an if-statement in the selection changed event of the combobox.
if(combobox.SelectedIndex == 0){
//Do this when the first item is selected
}else{
//Do this when the second item is selected
}
or you can check the values instead of the indexes depending on how many items you have in your combobox.
To show or hide controls depending on the user input you can change the visibility property of the controls :
button1.Visible = false;
button1.Visible = true; //Assuming you use Windows Forms and not WPF
But your question is pretty vague, so I can't give a full answer.
There are many ways to do what you want, this is one of them. You have to be more specific to get a better answer.

Multiple combo boxes bound to same source with conditional visibility on items

Unlike many questions related to this, I'm not having an issue with all combo box values being changed at when changing one combo box selection.
My problem is that I want to change the visibility of certain items when they are selected in the other list. I have two input port combo boxes and when I select port 5, say, on the first one, I want port 5 to not appear in the drop down for the second combo box.
I've tried this solution How to set combox item visibility? as it looked very promising but it won't let me cast from string to ComboBoxItem in the code-behind.
What else am I to do? I thought of creating a style in the XAML itself, but I can't quite figure out the conditions to use within the XAML and can't seem to find any topics over it. Lastly, I also have conditions in the setters for my input properties to check that the value the port is being set to is not the same as the other port, but it's not seeming to do anything for the view.
Are you using an ObservableCollection? This would allow for two way data binding whereas your UI will reflect the contents of each ObservableCollection in realtime if added to or removed from in an event. In another scenario, I had to apply a custom object to bind to in order to determine whether or not to show it, however, it was not the contents of a combobox, which are harder to access.

WPF Google-style ComboBox - AutoSuggestion

I want to have a Input field where I can input a string. That string could be a new item for that field or I choose to select an existing item. So I do not want Auto-Completion, but Auto-Suggestion which allows me to add entries to the ItemsSource by typing them in.
Basically it is like a normal WPF Combobox with
IsEditable="True"
But how can I get the ComboBox to reduce the list of suggestions to the string I input?
I don't want the ComboBox to present all Items of ItemsSource for selection, but only the ones that contain the string I input.
Can I do it due just setting some ComboBox properties?
For this propose you can use open source solutions like WPF AutoComplete TextBox control or other Autocomplete solutions
For this, I use the DevExpress library. If the ComboBoxEdit is configured correctly, it will auto display a drop down list which is continuously filtered by what the user types. Make sure you set the Mode to Contains, so it matches on any part of what the user types. Users love it as they can quickly narrow down the list of items to select from.
For the record, I am not affiliated with DevExpress. I'm sure Telerik has an equally good control as well.

C# ComboBox for IP addresses

I need a custom combo box that holds IP addresses. I have a custom control that holds an IP address(that actually is a panel with 4 textboxes). I already tried adding other controls to a normal combo box, such as a button and a textbox. I get no exceptions but I would expect to see the item in the drop-down list, instead i get a blank line for each item.
My first thoughts about this would be to extend the ComboBox control. What would you suggest?
A combo box is basically a textbox and a (usually) button-activated listbox combined for convenience. If it's not convenient you could implement your own dropdown functionality. Put a button next to your textboxes that display a listbox and when an item is selected from the listbox, put the values in the appropriate textboxes. In other words, don't try to extend the combo box, try to re-construct a similar control based on similar components.
It's not too difficult to override the ComboBox so I suppose you could create a custom ComboBox to show your own control that would be a container showing multiple of your IP Address controls.
Here's a blog article by JaredPar showing how to get started, just replace the m_form with your own custom container control.
You can hold the ip-addresses in a listbox, even in a combobox or what ever you want. Do not forget how your coding is, if you have an oop based tcp-socket program than no cross thread exception will be thrown. the codes shall be like ListBox.Items.Add(ipaddress) or ComboBox.Items.Add(ipaddress) ...
In controls you may hold only the ip-addresses, if you want to store the socket objects use Dictionary ... Your answer is not clear, so i've answered on possibly situations.

Combobox with clickable items

Good day S-O
Need help in developing a Custom combobox.
I should be able to display items like
10
20
30
Custom...
whenever i click Item 'x' i should get a pop up window to enter some value
My question is ...Is it a good idea to display an additional windows form with just a textbox control in it or is there any other better approach in such scenarios ?
Two Ideas-
As #Marcel stated in his comment, you can use a ComboBox with its DropDownStyle set to DropDown (not DropDownList). This will allow a user to select from the list or enter their own value. From there, you can do validation of the value if necessary.
If you need to be more explicit about a custom option (as opposed to the first idea, where it is not entirely obvious that you can enter a custom value), you could have a ComboBox with DropDownStyle set to DropDownList, a TextBox below it, and two RadioButtons that will enable/disable these to make them mutually exclusive.
I err against using popup messages/form whenever possible. I think it makes the application look kind of hacky, IMHO.
you may use a hidden textbox beside the combobox, and show it only if the used selects the Custom item

Categories