Очистить текст comboBox, чтобы можно было выбрать значение заново
Здравствуйте, есть много текст боксов в проге и есть пару комбо боксов.
Когда я их всех заполняю и добавляю эти данные в таблицу, я нажимаю кнопку «очистить заполненные поля» и поля очищаются. С текст боксами все хорошо, они очищаются с помощью таких строчек
1 2 3 4 5 6 7 8
surnameTextBox.Clear(); nameTextBox.Clear(); patronymicTextBox.Clear(); nameTextBox.Clear(); scorceTextBox.Clear(); numberTextBox.Clear(); numberSearchTextBox.Clear(); surnameSearchTextBox.Clear();
а вот с комбо боксами проблема, метода Clear у них нет.
и получается, что все поля у меня очистились и туда можно сразу запись новую писать, а комбо бокс остался как и был заполненным. Как сделать чтобы он тоже очистился и запись можно было заново выбрать?
Удалить элементы из combobox

Проверить образуют ли элементы массива возрастающую последовательность. Удалить элементы в отрезке
Помогите пожалуйста решить задачу, как — то самому не получается. Ввести одномерный массив k =.
Удалить из массива нулевые элементы, передвинув на их место следующие элементы без нарушения порядка
ищу решение еще одной задачи =) Задан массив действительных чисел. Удалить из массива нулевые.
Удалить повторы в ComboBox
Пробовала сделать вариантом написанным ниже, но не получилось for i:=1 to.

Как удалить строку в ComboBox
Доброго времени суток. Пишу программу и надо удалить строку с названием, которое забито в Edit1 .
133 / 133 / 29
Регистрация: 17.09.2010
Сообщений: 288
skilllab, можно так:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
private Liststring> items = new Liststring>() { "1", "2", "3", "4", "5" }; private int j = -1; public Form1() { InitializeComponent(); foreach (string s in items) { listComboBox.Items.Add(s); } } private void delButton_Click(object sender, EventArgs e) { j = listComboBox.SelectedIndex; listComboBox.Items.Clear(); listComboBox.Items.Add(items[j]); }
93 / 93 / 19
Регистрация: 25.12.2010
Сообщений: 316
1 2 3
string s = comboBox1.SelectedItem.ToString(); comboBox1.Items.Clear(); comboBox1.Items.Add(s);
52 / 52 / 15
Регистрация: 22.02.2011
Сообщений: 87
1 2 3 4
var buf = comboBox2.SelectedItem; comboBox2.Items.Clear(); comboBox2.Items.add(buf); comboBox2.SelectedItem = buf;
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
Помогаю со студенческими работами здесь

удалить элемент из combobox по dateitem
собственно сабж, есть combobox с элементами 5 и их кодами строка 1 — dateitem = 4 строка 2 -.

Удалить запись из ComboBox.Items
Здравствуйте. Пожалуйста подскажите как из компотента ComboBox удалить запись которая.
Как удалить выбранную строку из Combobox
Как удалить выбранное значение из комбобокс. Removeitem не помогает, выдает ошибку. Я попытался.
Сделать невидимым или удалить ComboBox
Подскажите пожалуйста, можно ли в WinApi удалить комбобокс или сделать его невидимым? Я пока.
Помогите очистить значение Комбобокса
А вот как сделать так, если такой элемент в комбобоксе есть, а в int a; он не поступил то его из комбобокса удалить, то есть: Есть в комбобоксе вот такие строки или они остались от предыдущего запроса(1,2,3,4,5 ну и т.д) а в int a поступили вот такие строки (1,3,5) То нужно удалить из комбобокса 2 и 4 вот как это можно сделать, помогите пожалуйста)
void ss() < AddStringToCombobox(comboBox1, 1); //первый параметр это какой комбобокс AddStringToCombobox(comboBox1, 3);// второй это какое значение AddStringToCombobox(comboBox1, 5); >
Отслеживать
user289178
задан 16 мар 2018 в 14:15
user289178 user289178
3 2 2 бронзовых знака
И как вы в int запихнёте несколько значений (1,3,5)?
16 мар 2018 в 14:20
@AlexanderPetrov ого, какой у вас ровненький счет 🙂
16 мар 2018 в 14:24
@AlexanderPetrov === А вы увидели что сверху приходит параметр ? Я говорил что приходят вот такие параметры(1,3,5). я вызываю его внизу AddStringToCombobox(comboBox1, 1); AddStringToCombobox(comboBox1, 3); AddStringToCombobox(comboBox1, 5);
16 мар 2018 в 14:26
Например, добавьте в класс поле private List
How do I clear a combobox?
I have some combo-boxes that are set up as drop down lists, and the user can pick a number in them. I also have a Clear button that should clear the text from the combo boxes but I can’t seem to get it. I’ve tried:
//doesn't work cboxHour.Text = "";
//doesn't work cboxHour.ResetText();
This seems like it should be so straight forward but I’m just not getting it.
57.4k 13 13 gold badges 101 101 silver badges 122 122 bronze badges
asked Feb 17, 2012 at 1:51
Fuzz Evans Fuzz Evans
2,893 11 11 gold badges 44 44 silver badges 63 63 bronze badges
possible duplicate of How to clear combo box contents in vb.net
Feb 17, 2012 at 2:42
18 Answers 18
Did you try cboxHour.Items.Clear() ?
answered Feb 17, 2012 at 1:55
Daniel Mann Daniel Mann
57.4k 13 13 gold badges 101 101 silver badges 122 122 bronze badges
That’s the winner. I’ll mark you as the chosen answer when I can.
Feb 17, 2012 at 1:57
If your comboBox is data bounded then set comboBoxName.DataSource = null before Clearing
Oct 19, 2016 at 13:40
This is likely insufficient. Calling ResetText() as answered by @beanmf below is likely also required.
Nov 16, 2017 at 20:18
In case of ‘DataSource’ property of a combobox used, we have to assign null as follows : modeComboBox.DataSource = null; (modeComboBox.DataSource = new BindingSource(dict, null);)
Aug 8, 2019 at 5:44
If you just want to clear the current selection, but leave all of the items in the list, you can use:
cboxHour.SelectedIndex = -1
16.8k 8 8 gold badges 61 61 silver badges 75 75 bronze badges
answered Feb 17, 2012 at 2:43
12.4k 9 9 gold badges 45 45 silver badges 80 80 bronze badges
When I employ this, the selectedIndexChanged event fires. In SelectedIndexChanged event, I return out of the eventif SelectedIndex is -1.
Dec 17, 2013 at 20:27
When ComboBox is not data-bound, I’ve found I need both: Clear() removes the items but still leaves the SelectedItem ‘s text, while ResetText() removes that text. VS2008.
ComboBox.Items.Clear(); ComboBox.ResetText();
4,552 4 4 gold badges 53 53 silver badges 64 64 bronze badges
answered Mar 29, 2014 at 13:38
493 5 5 silver badges 7 7 bronze badges
Agreed on above. I was having the same problem in VS2013, where the 4 calls Items.Clear(), SelectedIndex=-1, SelectedText=string.empty, and SelectedText=string.empty was insufficient. Items.Clear() followed by ResetText() did the trick.
Nov 16, 2017 at 20:16
Cbo.Items.Clear();
Cbo.DataSource = null;
if you have a binding on it.
answered Aug 8, 2013 at 15:19
151 1 1 silver badge 2 2 bronze badges
Answer for your question is:
metroComboBox1.SelectedItem = null; anycomboBox1.SelectedItem=null;
133k 46 46 gold badges 347 347 silver badges 426 426 bronze badges
answered Nov 21, 2015 at 18:43
user5589898 user5589898
91 1 1 silver badge 2 2 bronze badges
combox.items.clear() deletes the items from the list while setting the selected item to null clears the selected data. excellent. thanks.
Jan 7, 2016 at 8:52
if you are having trouble setting the index to -1, try setting the selecteditem to null or nothing. This worked for me.
Mar 16, 2018 at 16:36
This is the real answer. It also solves an issue I had with .ResetText — then, I wasn’t able any more to programmatically re-load a selection. But .SelectedItem = null does the trick. Excellent! Thank you!
Oct 7, 2019 at 17:00
cboxHour.Items.Clear();
16.7k 6 6 gold badges 37 37 silver badges 44 44 bronze badges
answered May 28, 2013 at 22:43
user2415339 user2415339
191 1 1 gold badge 3 3 silver badges 4 4 bronze badges
Can you expand on your answer a little? It’s great if you can provide a little bit of context to your answer.
May 28, 2013 at 23:02
If you have applied datasource to combobox, then it will not be cleared as cmb.Items.Clear() .
For that you have to assign datasource null to combobox.
cmb.DataSource = null; cmb.Items.Clear();
8,420 15 15 gold badges 50 50 silver badges 83 83 bronze badges
answered May 5, 2015 at 7:27
Rohil Patel Rohil Patel
396 3 3 silver badges 8 8 bronze badges
If there is value binding part for your combobox. Use below code to clear its value:
cboxHour.SetSelectedIndex(-1);
4,042 7 7 gold badges 27 27 silver badges 52 52 bronze badges
answered Oct 15, 2018 at 13:58
arihanth jain arihanth jain
86 4 4 bronze badges
comboBox1.ResetText();
3,320 3 3 gold badges 28 28 silver badges 35 35 bronze badges
answered Mar 28, 2019 at 18:02
Engr Qamar Abbas Engr Qamar Abbas
59 3 3 bronze badges
While this code may solve the question, including an explanation of how and why this solves the problem would really help to improve the quality of your post, and probably result in more up-votes. Remember that you are answering the question for readers in the future, not just the person asking now. Please edit your answer to add explanations and give an indication of what limitations and assumptions apply.
Mar 28, 2019 at 18:27
Mine worked with:
ComboBox.removeAllItems();
If it doesn’t read that well its, remove all items.
44k 12 12 gold badges 98 98 silver badges 133 133 bronze badges
answered Sep 13, 2015 at 15:02
user5331024 user5331024
19 1 1 bronze badge
Combo Box, DropDown all are having the same logic to clear/remove all items from them and it is like below.
//For checkbox list cblTest.Items.Clear(); //For drop down list ddlTest.Items.Clear();
answered Jan 2, 2014 at 12:11
Tapan kumar Tapan kumar
6,799 1 1 gold badge 24 24 silver badges 26 26 bronze badges
private void Resetbtn_Click(object sender, EventArgs e) < comboBox1.Items.Clear(); // it will clear a combobox comboBox1.Items.Add("Student"); //then add combobox elements again. comboBox1.Items.Add("Staff"); >
7,022 16 16 gold badges 51 51 silver badges 59 59 bronze badges
answered Oct 18, 2015 at 6:57
user5458887 user5458887
1 1 1 bronze badge
In WPF You can try this code
answered Feb 6, 2017 at 7:34
Chaithanya Chaithanya
179 1 1 silver badge 3 3 bronze badges
You can try the below option for clearing the selected text and all items from the ComboBox.
comboBox1.SelectedIndex = -1; comboBox1.Items.Clear();
2,236 27 27 gold badges 31 31 silver badges 38 38 bronze badges
answered Jul 21, 2017 at 13:23
1 1 1 bronze badge
This worked for me when I added ComboBox.Focus()
ComboBox.Items.Clear(); ComboBox.ResetText(); ComboBox.Focus();
answered May 31, 2020 at 12:12
49 1 1 bronze badge
> Its work for me:
ComboCapacity.DataSource = null; ComboCapacity.Items.Clear(); ComboCapacity.ResetText();
answered Oct 23, 2021 at 12:10
Engr. Khuram Shahzad Engr. Khuram Shahzad
396 3 3 silver badges 14 14 bronze badges
My Soluce to Clear DropDownList ComboBox C# VS2022
ComboBox _ComboBox = new ComboBox(); _ComboBox.DropDownStyle = ComboBoxStyle.DropDownList; _ComboBox.DataSource = DataTablexxx; _ComboBox.DisplayMember = "xxxx"; _ComboBox.ValueMember = "Idn"; //Enable the form now this.Visible = true; this.ResumeLayout(false); this.PerformLayout(); //Select the item by ident saved _ComboBox.SelectedValue = Properties.Settings.Default.Idn;
On Event Button :
_ComboBox.SelectedIndex = -1; _ComboBox.SelectedItem = null;