获取所有客户端ID并将其存储在C#中的列表中

时间:2015-12-12 18:33:26

标签: c# combobox datasource

我正在编写应用程序,我希望获取所有客户端ID并将它们存储在列表中,以便在comboBox上将它们显示为DataSource。

像列表中的ClientId = 1,2,3一样。

            cln = new Client();

        List<String> getClients = new List<String>{ cln.Id };

        getClients.ElementAt(0);

        clientIdComboBox.DataSource = getClients;

编辑2:

List<Client> clients = new List<Client>();
        clients.Add(new Client() { Id = "1" });
        clients.Add(new Client() { Id = "2" });

        clientIdComboBox.DataSource = clients;

This is how it looks like when I added the above code. There are 2 but empty.

1 个答案:

答案 0 :(得分:0)

首先,您需要正确设置列表:

List<Client> clients = new List<Client();
clients.Add(new Client() { Id = 1});
clients.Add(new Client() { Id = 2});
[...]

clientIdComboBox.DataSource = clients;