如何从数据表中设置 DataGridViewComboBoxColumn 中的值? [英] how to set value in DataGridViewComboBoxColumn from a datatable?

查看:27
本文介绍了如何从数据表中设置 DataGridViewComboBoxColumn 中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

DataGridViewComboBoxColumn dgvcb = (DataGridViewComboBoxColumn)grvPackList.Columns["Units"];
                Globals.G_ProductUtility G_Utility = new Globals.G_ProductUtility();
                dgvcb.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
                G_Utility.addUnittoComboDGV(dgvcb);
                DataSet _ds = iRawMaterialsRequest.Select();
                grvPackList.DataSource = _ds.Tables[0];

问题是datagrid中的DataGridViewComboBoxColumn没有用表中的值选择,怎么可能从datasoure中设置DataGridViewComboBoxColumn的值

the problem is that the DataGridViewComboBoxColumn in the datagrid is not selected with the value in table how is it possilbe to set value of DataGridViewComboBoxColumn from datasoure

int i=0;
                foreach (DataRow dgvr in  _ds.Tables[0].Rows )
                {
                    grvPackList.Rows[i].Cells["Units"].Value = dgvr["Units"].ToString();
                    i++;
                }

此代码有效,但有没有不使用循环的解决方案?

this code is working but is there any solution with out using loops?

推荐答案

int i=0; 
 foreach (DataRow dgvr in  _ds.Tables[0].Rows )
                {
                    grvPackList.Rows[i].Cells["Units"].Value = dgvr["Units"].ToString();
                    i++;
                }

当我尝试这个时它工作正常

When i Tried this it worked fine

这篇关于如何从数据表中设置 DataGridViewComboBoxColumn 中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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