7 Replies - 456 Views - Last Post: 20 September 2012 - 10:36 AM Rate Topic: -----

#1 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 218
  • Joined: 25-April 11

using tab in a dropdown

Posted 20 September 2012 - 06:39 AM

Hey guys

I did not find any solution to that, searching on internet! Perhaps it might be a stupid question, but I have no idea how to solve it.

I have a dropdown, filled dynamically with items out of a DB. If I select an item with my mouse, everything works fine. If instead i write some letters in the dropdown and then click my tab, it fills automatically the dropdown with my desired item BUT the dropdown.SelectedIndex is -1 AND the dropdown.SelectedItem is "", same thing for SelectedText and SelectedValue! how is this possible, and how could i check for this and set the correct SelectedIndex or SelectedItem?

Thank you in advance

Is This A Good Question/Topic? 0
  • +

Replies To: using tab in a dropdown

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9179
  • View blog
  • Posts: 34,468
  • Joined: 12-June 08

Re: using tab in a dropdown

Posted 20 September 2012 - 06:54 AM

How are you adding the dataset to the combobox? What sort of setting are set on the combobox? I just threw together a quick example and have the combobox set to a 'drop down list' (so it doesn't edit)... and attached a two column datatable (one column is displayvalue and the other is value member)... and tracking the 'selected indexed change' event shows the right index being recorded when.. well.. it changes.
Was This Post Helpful? 0
  • +
  • -

#3 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 218
  • Joined: 25-April 11

Re: using tab in a dropdown

Posted 20 September 2012 - 07:10 AM

I fill a list with my DB-data and afterwards loop trough it.
supporter = supporter.OrderBy(i => i.id).ToList();
sup_dwn.Items.Clear();
sup_dwn.Items.Add("Alle Supporter");
foreach (USER item in supporter) //Info: my list has a custom class named USER, that's why I use "USER item in supporter"
{
    sup_dwn.Items.Add(item.name);
}


my combobox-settings are the followings
Attached Image
Attached Image
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9179
  • View blog
  • Posts: 34,468
  • Joined: 12-June 08

Re: using tab in a dropdown

Posted 20 September 2012 - 07:14 AM

Why are you not just assigning the list as the combobox's "datasource" and bind it that way?
Was This Post Helpful? 2
  • +
  • -

#5 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 218
  • Joined: 25-April 11

Re: using tab in a dropdown

Posted 20 September 2012 - 07:28 AM

because the list has more than one columns. the class USER consists of (at the moment) two columns "id" and "name". that means that supporter[0] for example has two values and i have to specify which one should be shown on my combobox.

well i do not know another way of doing it... is there a better one?
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3565
  • View blog
  • Posts: 11,074
  • Joined: 05-May 12

Re: using tab in a dropdown

Posted 20 September 2012 - 07:49 AM

Yes, use the DisplayMember (and ValueMember) properties of the ComboBox: http://msdn.microsof...playmember.aspx
Was This Post Helpful? 1
  • +
  • -

#7 Anthonidas  Icon User is offline

  • D.I.C Head

Reputation: 30
  • View blog
  • Posts: 218
  • Joined: 25-April 11

Re: using tab in a dropdown

Posted 20 September 2012 - 08:02 AM

ooh cool! thank you guys! i'll try it out this evening.

does this even solve my problem of tab-control?
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9179
  • View blog
  • Posts: 34,468
  • Joined: 12-June 08

Re: using tab in a dropdown

Posted 20 September 2012 - 10:36 AM

I am not sure.. I don't have time to try and replicate what ever you are doing, but yes.. setting the datasource to your table and specifying the string name of the columns you want to show (aka displaymember) and what the behind the scenes value (aka value member) does fire off the right information on selected index change events.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1