标题:给DataGridView中 DataGridViewComboBoxColumn列赋值
只看楼主
yemeng54
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2008-9-20
 问题点数:0 回复次数:0 
给DataGridView中 DataGridViewComboBoxColumn列赋值
我在DataGridView添加了一列DataGridViewComboBoxColumn列名units,为其建立一个模板
public class classComboData
    {
        private string m_display = string.Empty;
        private string m_value = string.Empty;

        public classComboData(string display, string value)
        {
            this.m_display = display;
            this.m_value = value;
        }
        public string Display
        {
            get { return this.m_display; }
            set { this.m_display = value; }
        }
        public string Value
        {
            get { return this.m_value; }
            set { this.m_value = value; }
        }

    }
//读取配置文件,取得所有的单位名称和其ID号
XmlNodeList unitName = mainfrm.class_ReadxmlDB.GetNodeList((int)classReadXML.AllXMLFile.unitsName);
if (unitName != null && unitName.Count > 0)
{
   DataGridViewComboBoxCell cellSex = new DataGridViewComboBoxCell();
   for (int i = 0; i < unitName.Count; i++)
   {
       string displayName = unitName.Item(i).Attributes["UnitName"].Value.ToString();
       string displayValue = unitName.Item(i).Attributes["ID"].Value.ToString();
//将单位名称添加到DataGridViewComboBoxCell
       cellSex.Items.Add(new classComboData(displayName, displayValue));
    }
       cellSex.DisplayMember = "Display";
       cellSex.ValueMember = "Value";
       units.CellTemplate = cellSex;   //设置列DataGridViewComboBoxColumn列名units的模板
       unitName = null;
 }
怎样再窗体加载时设置此列的默认值?
请各位帮帮忙!!!!!!!!!!!!!!
搜索更多相关主题的帖子: 赋值 DataGridView 
2008-09-20 19:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-234281-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.166948 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved