[英]C# Applying dataGridView Cell Value to DateTimePickerObject
normally i apply the string values like this: 通常我会像这样应用字符串值:
numID.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
but to insert it to a datetimepickerobject and change his value, I cant just use .Value like this: 但要将其插入datetimepicker对象并更改其值,我不能仅使用.Value像这样:
numStartDate.Value = dataGridView1.SelectedRows[0].Cells[2].Value;
How should I do this? 我应该怎么做? thx :) 谢谢 :)
What type is dataGridView1.SelectedRows[0].Cells[2].Value
? dataGridView1.SelectedRows[0].Cells[2].Value
是什么类型?
If this type of DateTime
, then do the cast: 如果是这种类型的DateTime
,则执行强制转换:
(DateTime)dataGridView1.SelectedRows[0].Cells[2].Value
If this type of a String
, then do the following: 如果此类型为String
,则执行以下操作:
DateTime.Parse(dataGridView1.SelectedRows[0].Cells[2].Value.ToString())
PS: BTW, better use real data source, not DataGridView.Rows. PS:顺便说一句,最好使用真实的数据源,而不是DataGridView.Rows。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.