【问题标题】:DataGridView CalendarColumn only appears when clickedDataGridView CalendarColumn 仅在单击时出现
【发布时间】:2012-09-14 15:04:31
【问题描述】:

按照这个例子:

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;
            }
        }  
    }

【问题讨论】:

  • @DJKRAZE 当然,我添加了一部分最初填充行的代码,但是设置 DataGridView 本身是通过设计器完成的,与 CalendarColumn 本身相关的代码与中相同我提供的链接。 :) 谢谢!

标签: c# .net winforms datagridview


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2013-02-16
    • 1970-01-01
    • 2011-03-13
    • 2013-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-26
    • 1970-01-01
    相关资源
    最近更新 更多