編輯datagridview儲存格

來源:互聯網
上載者:User

標籤:orm   image   selected   begin   cts   變數   hand   text   ide   

以這3種為例,最簡單的是第三種,直接讓儲存格處於可編輯狀態,當完成編輯後觸發CellEndEdit事件,最後對輸入的資料進行處理。

1 private DateTimePicker dtp = new DateTimePicker();2 private ComBox sellstyle = new ComBox ();//設定全域變數
View Code
 1 public PlanVindicateForm() 2         { 3             InitializeComponent(); 4             dgvReaschResult.Controls.Add(dtp);//在表單的建構函式裡將datetimepicker控制項加入 5             this.dgvReaschResult.Controls.Add(this.sellstyle);//combox控制項 6             this.sellstyle.Visible = false;//設定是否顯示 7             this.dtp.Visible = false; 8             this.dtp.Format = DateTimePickerFormat.Custom;//設定顯示格式 9             this.dtp.CustomFormat = "HH:mm";10             this.dtp.KeyDown += new KeyEventHandler(dtp_KeyDown);//註冊控制項用到的事件11             this.sellstyle.cbTypeBox.SelectedIndexChanged += new EventHandler(cbTypeBox_SelectedIndexChanged);12         }
View Code
 1 private void dgvReaschResult_CellClick(object sender, DataGridViewCellEventArgs e) 2         { 3             if ((e.RowIndex > -1) && (e.ColumnIndex > -1)) 4             { 5                 string dataPropertyName = this.dgvReaschResult.Columns[e.ColumnIndex].DataPropertyName; 6                 switch (dataPropertyName) 7                 { 8                     case "CanSellSeatCount": 9 10                         this.dgvReaschResult.BeginEdit(true);11                         this.Original = int.Parse(this.dgvReaschResult.Rows[this.dgvReaschResult.CurrentCell.RowIndex].Cells[e.ColumnIndex].Value.ToString());12                         return;13 14                     case "DrvTime":15                         this.dgvReaschResult.BeginEdit(true);16                         this._Rectangle = this.dgvReaschResult.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);17                         this.dtp.Size = new Size(this._Rectangle.Width, this._Rectangle.Height);18                         this.dtp.Location = new Point(this._Rectangle.X, this._Rectangle.Y);19                         this.dtp.Visible = true;20                         this.dtp.ShowUpDown = true;21                         this.dtp.Value = DateTime.Parse(this.SelectSchedule.DrvTime);22                         this.dtp.Focus();23                         this.originaTime = this.dtp.Value;24                         return;25 26                     case "SellStyleName":27                     this.dgvReaschResult.BeginEdit(true);28                     this._Rectangle = this.dgvReaschResult.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);29                     this.sellstyle.Size = new Size(this._Rectangle.Width, this._Rectangle.Height);30                     this.sellstyle.Location = new Point(this._Rectangle.X, this._Rectangle.Y);31                     this.sellstyle.Visible = true;32                     this.sellstyle.SelectedText = this.SelectSchedule.SellStyleName;33                     this.sellstyle.Focus();34                     this.sellStyleName = this.SelectSchedule.SellStyleName;35                     return;36                 }37                 this.dtp.Visible = false;38                 this.sellstyle.Visible = false;39             }40 41         }
View Code
 1  private void dgvReaschResult_CellEndEdit(object sender, DataGridViewCellEventArgs e) 2         { 3             if ((e.RowIndex > -1) && (e.ColumnIndex > -1)) 4             { 5                 try 6                 { 7                     string dataPropertyName = this.dgvReaschResult.Columns[e.ColumnIndex].DataPropertyName;//擷取選中儲存格的資料來源的名稱,即列名 8                     int seats = 0; 9                     int num2 = 0;10                     switch (dataPropertyName)11                     {12                         case "CanSellSeatCount";//第3種13                             {14                                 //對擷取到的資料進行處理15                                 break;16                             }17                         case "DrvTime"://第1種18                              //對擷取到的資料進行處理19                             break;20 21                         case "SellStyleName"://第2種22                             //對擷取到的資料進行處理23                             break;24 25                     }26                 }27                 catch (Exception exception)28                 {29                     this.ShowError("執行失敗!");30                 }31             }32 33         }
View Code

 

編輯datagridview儲存格

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.