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;
Related
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()
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;
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));
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
listBox2.Items.Add(listBox1.SelectedItem);
listBox1.Items.Remove(listBox1.SelectedItem);
this code runs but I should select one item. I want to know how pass the value without selection
If you don't have a selected item but only the index you can use RemoveAt, if you want to add it to the other list you need the object anyway so you can use the indexer:
object item = listBox1.Items[index];
listBox2.Items.Add(item);
listBox1.Items.RemoveAt(index);
If you want to add all items use a loop:
for (int i = 0; i < listBox1.Items.Count; i++)
{
listBox2.Items.Add(listBox1.Items[i]);
}
listBox1.Items.Clear();
Here's an example:
var i = 0;// let i as the index which you want it to be moved.
var targetItem = listBox1.Items[i];
listBox2.Items.Add(targetItem);
listBox1.Items.RemoveAt(i);
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 7 years ago.
Improve this question
how to prevent sorting in DataGridView?
Winforms?
for (int i = 0; i < this.dataGridView1.ColumnCount - 1; i++)
{
this.dataGridView1.Columns[i].SortMode = DataGridViewColumnSortMode.Programmatic;
}
I'll assume you mean sorting in a WPF DataGrid: Set CanUserSortColumns="False".
I am assuming you are talking about web page grid view
<asp:GridView AllowPaging=false ...
Or if it's a WinForms DataGridView you can set the sortmode of the columns as:
Column1.SortMode = NotSortable