Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Populate ComboBox from List
Message
From
22/06/2021 06:31:59
 
 
To
21/06/2021 18:30:25
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01681491
Message ID:
01681514
Views:
31
Well, well - first Barry points in a funny way to the solution of his problem, now this verification after the very friendly last hints by Bill & Naomi... Hope this grows to be the norm.

well done
thomas

>Generally, when I finally say 'enough' and ask a co-worker or post something here, I'm always afraid it's something stupidly simple. And it was. Yanno, it does help if you actually call the Start procedure. Who keeps forgetting that .Net console apps don't REALLY start where you think they do...
>
>That would be me.
>
>>Hi Dorris,
>>
>>Did you try tracing the code in the debugger to see if it's populated correctly?
>>
>>Also, few things I noticed which I would change:
>>
>>1. No need to declare a string variable for the year and convert to int while you can use int directly
>>
>>2. In your second sample, make sure the datatable is created and probably add ToList() at the end (You would need to add LINQ reference to get ToList() method )
>>
>>>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?
Previous
Reply
Map
View

Click here to load this message in the networking platform