DevExpress GridControl控件行內新增、編輯、刪除添加選擇框

1.首先到GridControl控件設計裏設置屬性Repository    (In-place EditorRepository)  以下圖(CheckEdit能夠不添加,這是本人根據本身需求添加的):sql

         主要設置兩個兩個屬性 NullText,Namespa

     2.綁定數據設計

        關鍵代碼以下:code

            

DataTable dt = dbHelp.GetDataSql("select TS_NO,TS_NAME ,TS_LONGITUDE,TS_LATITUDE,TS_RANK from  dbo.LPTE_TS");

    grStation.DataSource = null;
    gvStation.Columns.Clear();
    grStation.DataSource = dt;

    gvStation.Columns["TS_NO"].Visible = false;
    gvStation.Columns["TS_NAME"].Visible = true;
    gvStation.Columns["TS_NAME"].Caption = "名稱";
    gvStation.Columns["TS_NAME"].VisibleIndex = 1;
    gvStation.Columns["TS_RANK"].Visible = true;
    gvStation.Columns["TS_RANK"].Caption = "等級";
    gvStation.Columns["TS_RANK"].VisibleIndex = 2;
    gvStation.Columns["TS_LONGITUDE"].Caption = "經度";
    gvStation.Columns["TS_LATITUDE"].Caption = "緯度";

     

    GridColumn addLinkHiper = new GridColumn();
    addLinkHiper.Caption = "新增";
    addLinkHiper.Visible = true;

    addLinkHiper.ColumnEdit = stationAdd;
    gvStation.Columns.Add(addLinkHiper);
    addLinkHiper.VisibleIndex = 5;

    GridColumn editLinkHiper = new GridColumn();
    editLinkHiper.Caption = "編輯";
    editLinkHiper.Visible = true;

    editLinkHiper.ColumnEdit = stationEdit;
    gvStation.Columns.Add(editLinkHiper);
    editLinkHiper.VisibleIndex = 6;

    GridColumn delLinkHiper = new GridColumn();
    delLinkHiper.Caption = "刪除";
    delLinkHiper.Visible = true;

    delLinkHiper.ColumnEdit = stationDel;
    gvStation.Columns.Add(delLinkHiper);
    delLinkHiper.VisibleIndex = 7;

    gvStation.BestFitColumns();

 

 

            以上數據已所有綁定完成blog

    3.觸發事件事件

            在上圖中點擊事件Click,新增很少說,彈出新窗體便可 ip

 

//編輯
    private void stationEdit_Click(object sender, EventArgs e)
    {
        int[] selectRows = gvStation.GetSelectedRows();
        //賦值
        int tsNo = Convert.ToInt32(gvStation.GetRowCellValue(selectRows[0], "TS_NO"));  //TS_NO是控件列名

        //具體操做因人而異

       ......
    }   

     //刪除
    private void stationDel_Click(object sender, EventArgs e)
    {
        if (MessageBox.Show("肯定刪除所選數據?", "刪除提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
        {

    int[] selectRows = gvStation.GetSelectedRows();
    //賦值
    int  tsNO = Convert.ToInt32(gvStation.GetRowCellValue(selectRows[0], "TS_NO"));

           //寫sql語句執行刪除操做就能夠了。
        }

    }

 

 

 

最後貼一張效果圖:it

相關文章
相關標籤/搜索