回复 4楼junlingzhu2002的帖子
我给你个SampleCode,有些地方可能不是很完善,请你再修改一下。
使用自定义DateTimePickerCell来实现。
- public class MyDateTimePickerCell : DateTimePickerCell
- {
- protected override void PaintCellForeground(CellPaintingEventArgs e)
- {
- if (this.GcMultiRow != null && e.FormattedValue != null)
- {
- if (this.ShouldDisplayText(e.FormattedValue, e.RowIndex, e.CellIndex))
- {
- base.PaintCellForeground(e);
- }
- }
- else
- {
- base.PaintCellForeground(e);
- }
- }
- bool ShouldDisplayText(object value, int currentRowIndex, int cellIndex)
- {
- for (int i = currentRowIndex - 1; i >= this.GcMultiRow.FirstDisplayedCellPosition.RowIndex; i--)
- {
- if (i == -1)
- {
- break;
- }
- object valueAbove = this.GcMultiRow.GetValue(i, cellIndex);
- if (valueAbove == null)
- {
- return true;
- }
- if (object.Equals(((DateTime)value).Date, ((DateTime)valueAbove).Date))
- {
- return false;
- }
- }
- return true;
- }
- }
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- this.gcMultiRow1.Template = Template.CreateGridTemplate(new Cell[] {
- new MyDateTimePickerCell() {Format = DateTimePickerFormat.Short},
- new TextBoxCell(),
- new TextBoxCell()});
- this.gcMultiRow1.RowCount = 5;
- this.gcMultiRow1.Scroll += gcMultiRow1_Scroll;
- }
- void gcMultiRow1_Scroll(object sender, ScrollEventArgs e)
- {
- this.gcMultiRow1.InvalidateCell(0, 0);
- }
- }
复制代码 |