Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Populate ComboBox from List
Message
From
21/06/2021 15:41:42
 
 
To
21/06/2021 15:31:59
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01681491
Message ID:
01681493
Views:
22
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?
"You don't manage people. You manage things - people you lead" Adm. Grace Hopper
Pflugerville, between a Rock and a Weird Place
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform