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

如下爲內容以圖片居多1234表示點擊順序html

先新增一行 操做和新增數據行同樣sql

a

打開ColumnEdit  選擇new ButtenEdit  new上方會出現一個系統命名的buttonide

命名能夠更改必須在下發name中更改 是行的name學習

 

                         二

                         

 

                            

                              

                                

 

進入click事件就和普通的按鈕同樣了 能夠編寫本身的代碼了this

一下代碼是設計器中的代碼 供你們參考spa

// gridColumn_update
this.gridColumn_update.Caption = "修改";
this.gridColumn_update.ColumnEdit = this.repositoryItemButtonEdit_update;
this.gridColumn_update.FieldName = "gridColumn_update";
this.gridColumn_update.Name = "gridColumn_update";
this.gridColumn_update.UnboundType = DevExpress.Data.UnboundColumnType.Decimal;
this.gridColumn_update.Visible = true;
this.gridColumn_update.VisibleIndex = 5;
// 
// repositoryItemButtonEdit_update
// 
this.repositoryItemButtonEdit_update.AutoHeight = false;
serializableAppearanceObject1.Options.UseTextOptions = true;
serializableAppearanceObject1.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Near;
this.repositoryItemButtonEdit_update.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph, "修改", -1, true, true, false, DevExpress.XtraEditors.ImageLocation.MiddleCenter, null, new DevExpress.Utils.KeyShortcut(System.            Windows.Forms.Keys.None), serializableAppearanceObject1, "", null, null, true)});
this.repositoryItemButtonEdit_update.Name = "repositoryItemButtonEdit_update";
this.repositoryItemButtonEdit_update.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
this.repositoryItemButtonEdit_update.ButtonClick += new DevExpress.XtraEditors.Controls.ButtonPressedEventHandler(th.repositoryItemButtonEdit_update_ButtonClick);

 

DevExpress控件的屬性太多了 還須要你們進行一步的學習使用理解.net

若有錯誤 或更好的方法 歡迎你們指指出設計

 

出處:https://blog.csdn.net/yueliangge910101/article/details/822576763d

=================================================================code

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

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

     2.綁定數據

        關鍵代碼以下:

            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();

            以上數據已所有綁定完成

    3.觸發事件

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

          //編輯
        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語句執行刪除操做就能夠了。
            }

        }

最後貼一張效果圖:

 

 

出處:https://blog.csdn.net/m1654399928/article/details/21951519

相關文章
相關標籤/搜索