There are combo boxes, and in them the value is constantly changing. How to make combobox check incoming value to him with his? Suppose it comes a value from another method, and if it does not find such a value, then it deletes it or adds it on the contrary. This is a miracle that I wrote, it will sort the data as a filter, which I chose is displayed (As on the site, or almost =))
- 2Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. - Kromster
- See there is one "Manufacturer" combo box, I choose it, and there the value let it be "Nissan" for example ... And all the other combo boxes (Model, speed, type, etc.) should be drawn on the selected Manufacturer ... Suppose the Nissan body type 'sedan' and in the combo box body type there is also a 'Lux' question how do I deluxe this suite and all other types, leaving everything appropriate for the Manufacturer - Entity
- The easiest way - they chose Nissan - they cleared all subsidiary combo boxes - filled them with suitable values. - Kromster
- Aah, it wasn’t there, when I clean everything, then I select again, the combobox clears the value before sorting the value by manufacturer, the Manufacturer’s value does not reach the sorting function, I just don’t know where or how to place it correctly so that the value You could choose the combo box, that is, so that it would reach the function, sort out, leave the selected value of this combo box ... Well, besides the Manufacturer, I can choose the body type and then the body type and then the Manufacturer, and so on - Entity
- oneIMHO, the question needs to be rewritten, adding to the new edition, what was dragged out of you in the comments. - Alexander Muksimov
1 answer
You need to fill in the second combo box after changing the values in the first one.
The scheme is as follows: At the first combo box subscribe to the SelectedValueChanged event. Example: https://msdn.microsoft.com/ru-ru/library/system.windows.forms.listcontrol.selectedvaluechanged(v=vs.110).aspx
In the event handler for changing the value of the first combo box, see which value is selected. Based on this, fill in the remaining combo boxes:
private void ComboBox1_SelectedValueChanged(object sender, EventArgs e) { if (ComboBox1.SelectedIndex != -1) { var selectedManufacturer = ListBox1.SelectedValue.ToString(); // производитель найден, установим данные в других списках SetManufacturerValues(selectedManufacturer); } } private void SetManufacturerValues(string manufacturer) { ComboBoxBodyType.Items = BodiesDataSource.Where(b => b.ManufacturerName == manufacturer); ... // остальные свойства } In the given example, the body type is set for the selected manufacturer. From a certain source of data about body types - you will have your own - we choose only those that correspond to the manufacturer. And we use them as a data source for the drop-down list.
- oneThank you for the answer, but I already have this filling structure) I have a different problem, I can not clear combo boxes, I’d rather clear it, but nothing happens when I select, that is, it first deletes all elements of the Combobox, and the function asks what you tell me brought, and combobox "Empty" ... 'I can not force it --------------------- I have all the Combobox subscribed to events, and when I call it first clears all the elements, and then has no idea what I chose ... I’m wondering how to properly clean combo boxes ... - Entity
- No need to clear combo boxes, just change the value of their Items property, assigning filtered values each time. Thus, you simply replace all the data, the old ones will go away, the new ones will appear. - Anton Shakalo
- Did not quite understand Items.Add? Items.AddRange? Items.Remove? I did not understand what you meant if you put Items.Add then it will simply add a new value to the existing lines - Entity
- Items = your data source. No need to clear, remove, nothing but assignment. The old data set will disappear - Anton Shakalo