我有一个带有下拉列表的comboBox,我想将选定的项目信息显示到Datagridview [英] i have a comboBox with drop list,i want to display the selected item information to the Datagridview

查看:47
本文介绍了我有一个带有下拉列表的comboBox,我想将选定的项目信息显示到Datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Point_Of_Sale.CustomerInfoDataSet.ItemsDataTable items = new CustomerInfoDataSet.ItemsDataTable();
            itemsTableAdapter.Fill(items);

            //dataGridView1.DataSource = items;
            comboBox1.DisplayMember = "ItemName";
            comboBox1.DataSource = items;

推荐答案

好吧,我想尝试帮助您,因为我了解您拥有combobox和datagridview,并且需要从中获取选定的项组合到网格....这很容易:
首先,您必须取消组合的选中或选中的项目


ok man i want to try to help you, as i understand you have combobox and datagridview and you need to bing the selected items from combo to grid....it is easy man:
first you must ckeck the selected or checked items of the combo


List<string> lstString = new List<string>();
        foreach (ListItem lItem in combo.Items)
        {
            if (lItem.Selected)
            {
                lstString.Add(lItem.Value);
            }
        }


这样,您可以将选定项的ID组合添加到字符串列表(ID列表)中,然后必须获取这些ID的对象项:


in this way you are adding the IDs of the selected items in combo into a list of strings(list of IDs), then you have to get the objects item of these IDs:

List<items> lst = new List<items>();//insted of Items put your class
        Items item = new Items();
        foreach(string s in lstString)
        {
            item = lstItem.FirstOrDefault(p => p.ID == s);
            lst.Add(item);
        }</items></items>


现在,您必须绑定网格,以为其提供数据源,该数据源是项目列表
grid.DataSource = lst;

注意:当您绑定组合框时,必须将项目放入
session ["]为使数据保持活动状态,我们需要通过它进行搜索

最好的问候


now you must bind the grid , to give it datasource which is the list of items
grid.DataSource = lst;

Note: when you bind you combobox you have to put items in
session[""] in order to keep data alive becuese we need to search via it

best regards


好的,我想帮助您,据我所知您拥有combobox和datagridview,并且您需要将选定的项目从combo到grid ....很容易男人:
首先,您必须取消组合的选中或选中的项目


ok man i want to try to help you, as i understand you have combobox and datagridview and you need to bing the selected items from combo to grid....it is easy man:
first you must ckeck the selected or checked items of the combo


List<string> lstString = new List<string>();
        foreach (ListItem lItem in combo.Items)
        {
            if (lItem.Selected)
            {
                lstString.Add(lItem.Value);
            }
        }


这样,您可以将选定项的ID组合添加到字符串列表(ID列表)中,然后必须获取这些ID的对象项:


in this way you are adding the IDs of the selected items in combo into a list of strings(list of IDs), then you have to get the objects item of these IDs:

List<items> lst = new List<items>();//instead of Items put your class
        Items item = new Items();
        foreach(string s in lstString)
        {
            item = lstItem.FirstOrDefault(p => p.ID == s);
            lst.Add(item);
        }</items></items>


现在,您必须绑定网格,以为其提供数据源,该数据源是项目列表


now you must bind the grid , to give it datasource which is the list of items

grid.DataSource = lst;



注意:当您绑定组合框时,必须将项目放入
session ["]为使数据保持活动状态,我们需要通过它进行搜索

最好的问候



Note: when you bind you combobox you have to put items in
session[""] in order to keep data alive becuese we need to search via it

best regards


这篇关于我有一个带有下拉列表的comboBox,我想将选定的项目信息显示到Datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆