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

Click here to load this message in the networking platform