How to clear a DropDownList c#? [duplicate] - c#

This question already has answers here:
Clearing a drop down list in C#
(2 answers)
Closed 8 years ago.
I am trying with this line of code :
comboxBox.items = null;
it's not working, i have an error.
Anyone can give me a hand ? Thanks.

You can try like this :
comboBox.items.Clear ();
or like this :
comboBox.dataSource = null;
depend if its datasource
if you want to show an empty selection , try this :
comboBox.selectedIndex = -1;
Hope this will help :)

comboBox.Items.Clear();
Should do the trick.
Items is a read-only property of the combo box, so you can't assign to it.

Related

Setting width of ComboBox autocomplete [duplicate]

This question already has answers here:
Combo box drop down width on suggest
(3 answers)
Closed 2 years ago.
In the WinForms combobox, the width of the drop-down can be set programmatically, as in the following example, code and screenshot:
myComboBox.DropDownWidth = 300;
For the combo box, I have enabled the autocomplete:
myComboBox.AutoCompleteSource = AutoCompleteSource.ListItems;
myComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
The autocomplete drop-down appears as follows:
How can I set the width of the drop-down containing the suggested items?
I believe that is not possible. You'll probably have to create a custom control to achieve what you need.
Here some information that might be useful for you:
https://social.msdn.microsoft.com/Forums/windows/en-US/f88f37c9-95f9-4f2f-84b5-e262f49a009d/autocomplete-suggest-box-can-this-be-influenced?forum=winformsdesigner

.NET winform - Checkbox nullReferenceException [duplicate]

This question already has answers here:
What is a NullReferenceException, and how do I fix it?
(27 answers)
Closed 8 years ago.
When im trying to set checkbox.checked, i got null refedence exception. I dont know why, it looks like that checkbox isnt initialized.
There is my code
public UpdateProduct(DataGridViewRow row,Form1 form)
{
this.row = row;
this.form = form;
product = row.DataBoundItem as object;
visibilityCheckBox.Checked = true;
InitializeComponent();
}
Exception is firing in line visibilityCheckBox.Checked = true;
Please can anybody help me with this issue ? Thanks much !
I guess you didn't call InitializeComponent before, and since you are trying to set it before the call to InitializeComponent, visibilityCheckBox will be null.
Call InitializeComponent first or write another method that does only update the created UI elements.

IsDefault and IsDefaulted properties [duplicate]

This question already has answers here:
What's the difference between a button with IsDefault and IsDefaulted?
(3 answers)
Closed 8 years ago.
Can you please explain me what do these two properties?
Button.IsDefault and Button.IsDefaulted
I tried to run the example on MSDN but it works.
http://msdn.microsoft.com/en-us/library/system.windows.controls.button.isdefault(v=vs.110).aspx
I should create a method?
Can you make me two simple example please?
IsDefault can be got or set, to make the button the default when enter is pressed.
IsDefaulted is the ReadOnly property that shows if the button is default. This is used in the code behind.
For example, if you want your button to be the default button for the form, use
<Button Name="btn_whatever" IsDefault="True"/>
Then you can do in the C#
if(btn_whatever.IsDefaulted)
//do something
or
if(btn_whatever.IsDefault)
//do something

Open ComboBox DropDown programmatically [duplicate]

This question already has answers here:
Winforms: how to open combobox properly?
(5 answers)
Closed 9 years ago.
Is it possible to directly open the WindowsForms combobox programmatically? Have not found a method or property to do so. If not, what are possible solutions that do not involve a lot of hacking.
Use ComboBox.DroppedDown Property:
comboBox1.DroppedDown = true;

How to implement search in listbox wp7? [duplicate]

This question already has answers here:
Filtering an ObservableCollection?
(3 answers)
Closed 2 years ago.
How to implement search in listbox(ObservableCollection)? Is the wp7 has something default for this?
You should look into the Autocomplete textbox which is part of the Silverlight toolkit
i think the control of Autocomplete can help you.

Categories