【发布时间】:2022-12-07 04:33:58
【问题描述】:
this is my calendar 我怎样才能做到当我点击日历中的某个日期(添加新任务)时,自动将其设置在 StartDate 列中?
我不想对该列使用 DateTimePicker。
【问题讨论】:
标签: c# datagridview calendar user-controls datagridviewcolumn
this is my calendar 我怎样才能做到当我点击日历中的某个日期(添加新任务)时,自动将其设置在 StartDate 列中?
我不想对该列使用 DateTimePicker。
【问题讨论】:
标签: c# datagridview calendar user-controls datagridviewcolumn
要从用户控件日历设置 DataGridView 控件的 StartDate 列,您可以使用 DataGridView.CurrentCell 属性指定应编辑哪个单元格,然后将该单元格的值设置为从日历控件中选择的日期。
这是一个如何做到这一点的例子:
// Set the current cell to the StartDate column in the first row
dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells["StartDate"];
// Set the value of the current cell to the selected date from the calendar control
dataGridView1.CurrentCell.Value = calendar1.SelectedDate;
请记住,只有当 DataGridView 控件具有名称为“StartDate”的列并且控件中至少有一行时,这才会起作用。您可能需要调整代码以满足您的特定需求。
【讨论】: