Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Populate ComboBox from List
Message
From
21/06/2021 16:50:58
 
 
To
21/06/2021 15:41:42
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01681491
Message ID:
01681499
Views:
22
Sorry, I haven't used a list in that way with a combo box, so I'm guessing here.
Do you think you might have to assign a value member?



>No, in that the Combobox is painted on the form, but when you click on the down arrow, it shows a blank. Tried to take a screen shot, but it closes when the form loses focus.
>
>
>
>>>First thing I should mention, this is a windows form in a console app
>>>
>>>Now, having said that - I've got the following combobox that I want to have display 'this' year and the previous 3 years.
>>>
>>>So....
>>>
>>>    class YearList
>>>    {
>>>      public string YearNum { get; set; }
>>>      public int YearVal { get; set; }
>>>      public YearList(int v, string y)
>>>      {
>>>        YearVal = v;
>>>        YearNum = y;
>>>      }
>>>    }
>>>        string ThisYear = DateTime.Today.Year.ToString();
>>>        try
>>>        {
>>>          YearList[] list = new YearList[]
>>>          {
>>>          new YearList(0, "Select Year"),
>>>          new YearList(1,ThisYear),
>>>          new YearList(2, (Convert.ToInt32(ThisYear)-1).ToString()),
>>>          new YearList(3, (Convert.ToInt32(ThisYear)-2).ToString()),
>>>          new YearList(4, (Convert.ToInt32(ThisYear)-3).ToString())
>>>          };
>>>          cbYear.DataSource = list;
>>>          cbYear.DisplayMember = "YearNum";
>>>        }
>>>        catch (Exception em)
>>>        {
>>>          MessageBox.Show(em.Message);
>>>        }
>>>        this.ShowDialog();
>>>
>>>
>>>Generates no errors....also generates no display on the form.
>>>
>>>And whilst I'm here, I've got another combobox on the form that I'm trying to fill from a table with
>>>
>>>        DataTable Cnty = new DataTable("CntyTbl");
>>>        SqlDataAdapter CA = new SqlDataAdapter(Cntycmd);
>>>        CA.Fill(Cnty);
>>>        cbCnty.DataSource = Cnty;
>>>        cbCnty.DisplayMember = "TypeDesc";
>>>        cbCnty.ValueMember = "TypeCode";
>>>        cbCnty.Items.Insert(0, "all");
>>>        cbCnty.Items.Insert(0, "Select CSCD");
>>>
>>>
>>>Generates no errors....also generates no display on the form.
>>>
>>>So, what am I missing?
>>
>>Do the list and combo box appear on the form?
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform