I have a combo box on a windows form that I am trying to populate with a list of clients. I have a List of Tuple with three values (var clients = new List<Tuple<int, string, string>>();
) I am getting data from a SQL call returning a clientID
, clientName
, and path
.
The issue I am having is, my combo box is displaying (1, companyName, c:\Path)
which is the first value of my list, but what I really want to display is the companyName
(Item2 in the tuple) and not the other data.
If my clients
variable was just a Tuple instead of a list of Tuple I would be able to do this:
comboBoxClients.DisplayMember = clients.Item2;
comboBoxClients.ValueMember = clients.Item1
Here is the code I tried to use which didn't work:
var clients = new List<Tuple<int, string, string>>();
clients = GetClients();
comboBoxClient.DataSource = clients;
comboBoxClient.DisplayMember = clients[0].Item2;
Is there a way I can set the DisplayMember
to the second item of my tuple in the list? Is there something else I should be using instead of a tuple? Any help with this is appreciated.
Try setting comboBoxClient.DisplayMember = "Item2";
DisplayMember
should be a string declaring the name of the property to be diplayed. See here: http://msdn.microsoft.com/de-de/library/system.windows.forms.listcontrol.displaymember%28v=vs.110%29.aspx
Handling of ValueMember
is the same.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With