如何将日期Cell DataGridView的值转到DateTimePicker中?
第一件事转到DataGridView事件Mouseclick,并写下以下代码:
DateTime dateValueOftheCell = DateTime.Parse(dataGridView1.CurrentRow.Cells[4].Value.ToString());
dateTimePicker1.Value = dateValueOftheCell.Date;
在我的情况下,我的datagridview在第5列中具有date值,即索引4
索引从0开始,索引值=列数-1 5-1 = 4
First thing go to datagridview event MouseClick, and write the code below:
DateTime dateValueOftheCell = DateTime.Parse(dataGridView1.CurrentRow.Cells[4].Value.ToString());
dateTimePicker1.Value = dateValueOftheCell.Date;
in my case my datagridview has the date value in the 5th column which is the index 4
index start from 0, index value = number of columns - 1
5 - 1 = 4
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该将DataGridView DataSource属性设置为BindingSource,该属性可以轻松访问当前行数据。另外,您可以索引到bindingsource,以获取特定行,如下所示,很难编码以获取第三行数据。
You should setup the DataGridView DataSource property to a BindingSource which allows easy access to the current row data. Also you can index into the BindingSource to get a specific row as shown below which is hard coded to get the third row data.
使用LINQ,我为鼠标单击事件创建了一个简单的代码。
我希望它有帮助!
Using LINQ, I've created a simple code for Mouse Click event.
I hope it helps!