1.添加表头

            sgc.PrimaryGrid.SelectionGranularity = SelectionGranularity.Row;//点击选中一行
            DevComponents.DotNetBar.SuperGrid.GridColumn gc = null;

            gc = new DevComponents.DotNetBar.SuperGrid.GridColumn("ID");
            sgc.PrimaryGrid.Columns.Add(gc);
            gc = new DevComponents.DotNetBar.SuperGrid.GridColumn("类型编码");
            sgc.PrimaryGrid.Columns.Add(gc);

2.添加数据 加一行

sgc.PrimaryGrid.Rows.Add(new GridRow(new object[] { "a", "b" }));//也就是加一个GrindRow对像 

 

3.设点击选中一行后 取第一行第一列的值

SelectedElementCollection col = sgc.PrimaryGrid.GetSelectedRows();//选中的行集合

if (col.Count > 0)
    {
      GridRow gr = (col[0] as GridRow);//把第一行转为GridRow 
      fac.ID = int.Parse(gr.Cells[0].Value.ToString());//取第一列的Value转一下

      //等效于int id= int.Parse((sgc.PrimaryGrid.GetSelectedRows()[0] as GridRow).Cells[0].Value.ToString());
     }

 4.增加一个下拉框

 4.1

using DevComponents.DotNetBar.SuperGrid;
using System;
using System.Windows.Forms;

namespace TestForm
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.Load += Form1_Load;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            GridColumn col = new GridColumn("这是一个下拉框");
            col.HeaderText = "这是一个下拉框";
            col.Name = "这是一个下拉框";

            col.AutoSizeMode = ColumnAutoSizeMode.DisplayedCells;
            col.EditorType = typeof(DefineGridCB);
            col.EditorParams = new object[] { new object[] { "第一个", "第二个" } };


            superGridControl1.PrimaryGrid.Columns.Add(col);
        }

        //自定义控件
        public class DefineGridCB : GridComboBoxExEditControl
        {
            public DefineGridCB(object source)
            {
                DataSource = source;
            }
        }

        //增加一行
        private void buttonItem1_Click(object sender, EventArgs e)
        {
            superGridControl1.PrimaryGrid.NewRow(true);
        }
    }
}
View Code

相关文章: