我有一个DataGridview,在C#窗口窗体中有1个单列和5行。如何将日期时间控件仅添加到第2行和第4行?
// Create a new DateTimePicker control
DateTimePicker dateTimePicker = new DateTimePicker();
dateTimePicker.Format = DateTimePickerFormat.Short;
// Create a DataGridViewComboBoxCell
DataGridViewComboBoxCell comboBoxCell = new DataGridViewComboBoxCell();
// Add the DateTimePicker control to the ComboBox cell
comboBoxCell.Value = dateTimePicker;
// Set the ComboBox cell to the specific row and column
dataGridView1.Rows[1].Cells[1] = comboBoxCell;
dataGridView1.Rows[3].Cells[1] = comboBoxCell;
1条答案
按热度按时间yvfmudvl1#
请看这段代码,它可以完成您正在寻找的任务。单击单元格后,可以根据RowIndex决定是否显示日期时间控件。
As demonstrated here