gridView 单元格绑定不同控件方法

1、主要代码:

private void Form3_Load(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("HZ");
            dt.Columns.Add("PY",typeof(object));         
            dt.Rows.Add(1,1);
            dt.Rows.Add(2,2);
            gridControl1.DataSource = dt;
        }

        private void gridView1_CustomRowCellEdit(object sender, DevExpress.XtraGrid.Views.Grid.CustomRowCellEditEventArgs e)
        {
            if (e.Column.FieldName == "PY")
            {
                if (e.RowHandle == 0)
                {
                    RepositoryItemRadioGroup rig = new RepositoryItemRadioGroup();
                    RadioGroupItem item = new RadioGroupItem();
                    item.Description = "S";
                    item.Value = 1;
                    RadioGroupItem item1 = new RadioGroupItem();
                    item1.Description = "Y";
                    item1.Value = 3;
                    rig.Items.Add(item);
                    rig.Items.Add(item1);
                    rig.ParseEditValue += rig_ParseEditValue;
                    e.RepositoryItem = rig;
                }
                else if (e.RowHandle ==1)
                {
                    RepositoryItemRadioGroup rig1 = new RepositoryItemRadioGroup();
                    RadioGroupItem item2 = new RadioGroupItem();
                    item2.Description = "M";
                    item2.Value = 2;
                    RadioGroupItem item3 = new RadioGroupItem();
                    item3.Description = "N";
                    item3.Value = 4;
                    rig1.Items.Add(item2);
                    rig1.Items.Add(item3);
                    e.RepositoryItem = rig1;
                }
            }
        }


2、效果图:

3、实例使用的是同一控件,使用不同控件只需将方法里面添加的控件更换即可。

posted @ 2014-12-18 11:22  曼彻斯特联队  阅读(420)  评论(0编辑  收藏  举报