How can I delete all the items in combo box? [closed] - c#

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have a ComboBox control with the DropDownStyle properties set to DropDownList. I want to replace the list of items with some new items at some points in the form but it concatenates the new items with the old items. How can I delete the old items and place new items in the combo box?
I am trying something like that:
this.selectAttribute.Items.AddRange(new object[] {
"Airport_Name", //New items
"City",
"Country"});

You could try clearing the items first:
this.selectAttribute.Items.Clear();

Use the .clear() functionality:
this.selectAttribute.Items.clear()

Related

i want add value number to first element of of text box [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
txtpayAmount.Text = gblFunction.ConvertTwoDecimal(
txtpayAmount.Text,
btn.Tag.ToString(),
txtpayAmount.SelectedText.Length);
txtpayAmount.Focus();
txtpayAmount.SelectionStart = txtpayAmount.Text.Length;
This is my code , am trying to add the value of button to textbox but its adding as last element of textbox.I want to add as first element
If I understand correctly (your question is confusing), you want prepend the text in a textbox.
If you want to do so you can do a txtBox.Value = 'ValueToPrepend' + txtBox.Value;

Find items in a string collection which contain another string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have a collection which has strings in it.
Such as:
"iphone x sadasd"
"IPHONE X s325g"
"Another string"
I am adding these strings in a listbox, but not all of them.
I want to add strings into a listbox based on the text entered in a textbox. e.g I might enter the text "iphone x "
So far I have tried:
if(collection.Contains(textBox1.Text));
{
listbox1.items.Add(//string that contains texbox1.text)
}
Use AddRange Method with Where
listbox1.Items.AddRange(collection.Where(x => x.Contains(textBox1.Text));

c# checklistbox check if item is selected [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
It my sound trivial but I can't get around. How do I know if item in checklistbox is selected ? I've got checklistbox with 3 items and I'd like to do some 'if then' statements. Basically ,if chkbox1.Checked Items 'ABC' is selected / checked then..
Thanks
CheckedListBox contains CheckedItems property. You can get all checked items from this collection. Read here: MSDN
got this solved by using
GetItemCheckState(0) == CheckState.Checked
and using 0 first item ,1 second item etc.

How to create images in a Foreach Loop [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a List of objects and i want to create a Foreach loop which create images on my MainWindow separated by 50 pixels for example. I don't know if I have to create them in the desgner itself or if there's a way to create then place the images the one below the other in a command.
For example i have:
List<string> URIS = new List<string>();
foreach (var i in URIS)
{
//New image in MainWindow with source i
}
Remember that I want a "list" of images in my Window so that every image is below the last one.
Look into the ItemsControl. It has an ItemsSource property that takes a list and lays out its items into a visual list. You can use the ItemTemplate property to control exactly what type of visual is created from each list item, including things like spacing.

Combobox text when clearing items [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm dealing with the fact that when I clear items in a combobox programmatically, the text do not change and keep the last selected item.
How can I do it?
Try
comboBox.SelectedIndex = -1;
Or
comboBox.Items.Clear();
comboBox.ResetText();
Another way for combo boxes:
Populate
comboBox1.DataSource = new string[] { "", "bruce", "clark", "tony" };
Clear
comboBox1.DataSource = null;

Categories