如何将列表项绑定到datagridview

如何将列表项绑定到datagridview

本文介绍了如何将列表项绑定到datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从数据库填充的列表,我想将此列表绑定到数据网格,任何



的帮助将不胜感激。以下是我的代码:



i am having a list populated from a database, i want to bind this list to a datagrid, any

assistance will be appreciated. below is my code:

 public List<string> listUserNameDuplicate = new List<string>();
 public List<string> listUserName = new List<string>();
while (reader.Read())
                {

                    listUserName.Add(reader["FirstName"].ToString().ToUpper());
                    listUserNameDuplicate.Add(reader["LastName"].ToString().ToUpper());
                    listUserNameDuplicate.Add(reader["FirstName"].ToString().ToUpper());
                    listUserNameDuplicate.Add(reader["MiddleName"].ToString().ToUpper());
                    listUserNameDuplicate.Add(reader["ClassName"].ToString().ToUpper());

               }





i以这种方式呼叫列表:





i am calling the list in this way:

listBoxDuplicate.DataSource = Wr.listUserNameDuplicate.ToList();





it仅显示一行中的列表项,它们都是整数值,我想在数据网格中显示Firstname,LastName,MiddleName,ClassName作为标题文本,并且它们是



下面的相应记录。





我还想检查listUserName是否包含多个用户名。



任何帮助将不胜感激。在此先感谢。



it displays the list items in one row only, and they are all integer values, i want to display Firstname, LastName,MiddleName,ClassName as header text in the datagrid and their

corresponding records below.


And i also want to check whether the listUserName contains more than one username.

Any assistance will be appreciated. Thanks in advance.

推荐答案

这篇关于如何将列表项绑定到datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 04:05