DataGridView CalendarColumn仅在单击时显示

时间:2012-09-14 15:04:31

标签: c# .net winforms datagridview

遵循这个例子:

http://msdn.microsoft.com/en-us/library/7tas5c80.aspx

但是,在运行时,当我向DataGridView添加行并显示它们时,包含CalendarColumn的列是空白的,直到我单击它为止。然后,只要我点击其他任何地方,该列就会再次变为空白。因此,只有在您与之互动时才能看到它。

任何可能导致此问题的想法?

编辑:仅代码的相关部分。休息是通过设计师完成的。

        private void LoadScheduleView()
    {
        // Get the keys
        var scheduleNames = _schedules.Current.Keys;

        // Get the current scheduled objects based on the keys (layoutnames).
        foreach (var scheduleName in scheduleNames)
        {
            var schedule = _schedules.Current[scheduleName];
            // Add the already existing schedule to the data grid view.
            schedulesDataGrid.Rows.Add(schedule.Date, schedule.Layout, schedule.CloseAllWindows);
        }
        //schedulesDataGrid.Sort(schedulesDataGrid.Columns[0], ListSortDirection.Ascending);

        DateTime scheduledTime = new DateTime();
        var rowsToLoop = schedulesDataGrid.Rows;
        foreach (DataGridViewRow row in rowsToLoop)
        {
            scheduledTime = (DateTime)row.Cells[0].Value;

            if (scheduledTime < DateTime.Now)
            {
                schedulesDataGrid.Rows.Remove(row);
            }

            //This will happen in sorted list order, therefore the first time it's after DateTime.Now, it will be the next layout to launch.
            else
            {
                var indexOfNextSchedule = schedulesDataGrid.Rows.IndexOf(row);
                schedulesDataGrid.FirstDisplayedScrollingRowIndex = indexOfNextSchedule;
                //schedulesDataGrid.Rows[indexOfNextSchedule].Selected = true;
                break;
            }
        }  
    }

1 个答案:

答案 0 :(得分:1)

好像问题在于CalendarCell来自DataGridViewCell而不是DataGridViewTextBoxCell。如果我发现这会导致任何进一步的问题,我会报告回来......