2017-06-16 145 views
1

我在datagridview中有一個datetimepicker值。 (到達日期和出發日期) 這裏是屏幕截圖。 Screenshot 1如何將datetimepicker的值以另一種形式傳遞給另一個datetimepicker

此外,我有一個編輯窗體爲datagrid視圖中的值。

enter image description here

如何傳遞的DateTimePicker的值從DataGridView到第二形式的DateTimePicker值。

這裏是我的嘗試:

private void arrivaldgv_CellDoubleClick(object sender, DataGridViewCellEventArgs e) 
     { 
      edit edt = new edit(); 
      edt.label12.Text = this.label2.Text; 
      edt.label13.Text = this.arrivaldgv.CurrentRow.Cells[0].Value.ToString(); 
      edt.textBox1.Text = this.arrivaldgv.CurrentRow.Cells[1].Value.ToString(); 
      edt.textBox2.Text = this.arrivaldgv.CurrentRow.Cells[2].Value.ToString(); 
      edt.textBox3.Text = this.arrivaldgv.CurrentRow.Cells[3].Value.ToString(); 
     /* edt.dateTimePicker1.Value = this.arrivaldgv.CurrentRow.Cells[4].Value; problem here */ 
      edt.ShowDialog(); 
     } 

回答

1

嘗試System.Convert.ToDateTime方法:

edt.dateTimePicker1.Value = System.Convert.ToDateTime(this.arrivaldgv.CurrentRow.Cells[4].Value); 
+0

更快地工作,它的工作! –

+0

當然,在5分鐘:) –

1

可以使用DateTime.Parse方法:

edt.dateTimePicker1.Value = DateTime.Parse(this.arrivaldgv.CurrentRow.Cells[4].Value); 

大多數.ToX方法用一些實例內部的方法,這裏也是這種情況,其中m意味着這應該比Convert.ToDateTime()

相關問題