Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

C# Combobox ValueMember problem

$
0
0
Hi all,

I'm pretty new to the world of C# and .Net and enjoying it so far.

I'm having trouble setting the index value in a combobox. I'm using MySQL connector/Net and because it doesn't provide certain tools/extensions to work with Visual Studio I have to do certain things manually (which isn't  problem because it helps me understand C# and .Net better). :^)

My original intention was to take names and ids from a table and use the id as the index in the combobox list and the names as display. I get a full list of the names no problems. But the index is always the same, integers incremented with each item.

As you can see I've tried creating a table myself and it still doesn't work. You will  get a better idea of what I'm trying to achieve below.


                DataTable dsTbl = new DataTable("Category");
                dsTbl.Columns.Add("catid", typeof(int));
                dsTbl.Columns.Add("name", typeof(string));

                object[] row = newobject[2];

                row[0] = 28;
                row[1] = "Stupid";

                dsTbl.Rows.Add(row);

                catCombo.DataSource = dsTbl;
                catCombo.ValueMember = "catid";
                catCombo.DisplayMember = "name";


 


Appreciate any help anyone can offer!

Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>