By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,725 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,725 IT Pros & Developers. It's quick & easy.

Combobox selectedvalue = null

P: n/a
Jac

Hey,

How can I set the display value of a combobox empty? But all the posible
choices are available when I push the trianglebut.

Sometimes if I set the selecteditem = null it works, other times it don't
work and sometimes I receive an error 'Additional information: Value cannot
be null'.

this.CmbDataSource = SoortKwijtingList.Items; // Arraylist
this.Cmb.DisplayMember = "Omschrijving";
this.Cmb.ValueMember = "Id";
this.Cmb.SelectedItem = null;

I don't understand that, what is so unstable? Has it something to do with
the moment of databinding?

Thanks in advance
jac

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi Jac,

Set ComboBox.SelectedIndex = -1;
On Thu, 28 Apr 2005 22:34:18 +0200, Jac <Ja*@discussions.microsoft.com> wrote:

Hey,

How can I set the display value of a combobox empty? But all the posible
choices are available when I push the trianglebut.

Sometimes if I set the selecteditem = null it works, other times it don't
work and sometimes I receive an error 'Additional information: Value cannot
be null'.

this.CmbDataSource = SoortKwijtingList.Items; // Arraylist
this.Cmb.DisplayMember = "Omschrijving";
this.Cmb.ValueMember = "Id";
this.Cmb.SelectedItem = null;

I don't understand that, what is so unstable? Has it something to do with
the moment of databinding?

Thanks in advance
jac


--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2

P: n/a
Jac
Hey,

I have still something strange.

When I made my choice in the combobox and push the Cancel-button then I want
to show the previous values (the values I had before) and I do this now like
this :

f (kwijting.SoortKwijting == null )
this.Cmb.SelectedIndex = -1;
else
this.Cmb.SelectedValue = kwijting.SoortKwijting.Id;

This works fine. But then I push the Add-button (add new record). I want to
clean up all the values in the screen (want all my comboboxes, textfields
etc. are empty, so I can start to fill in the screen).
So, for the comboboxes I do this :

this.Cmb.SelectedIndex = -1;

If I look in 'QuickWatch" he changes my selectedindex not to -1, but to 1.
And so he gives me always the first choice in view of the combobox.

When I do it like this :
this.Cmb.SelectedIndex = -1;
this.Cmb.SelectedValue= -1;

Then the combobox view is empty.

I don't understand that I have to do 2 things. What can be wrong here?
Because selectedvalue is filled up? But that is normal?

Thanks for help.
Jac


"Jac" wrote:

Hey,

How can I set the display value of a combobox empty? But all the posible
choices are available when I push the trianglebut.

Sometimes if I set the selecteditem = null it works, other times it don't
work and sometimes I receive an error 'Additional information: Value cannot
be null'.

this.CmbDataSource = SoortKwijtingList.Items; // Arraylist
this.Cmb.DisplayMember = "Omschrijving";
this.Cmb.ValueMember = "Id";
this.Cmb.SelectedItem = null;

I don't understand that, what is so unstable? Has it something to do with
the moment of databinding?

Thanks in advance
jac

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.