简体   繁体   English

如何检查DataGridViewCalendarColumn的值是否已更改?

[英]How to check if the value of a DataGridViewCalendarColumn has been changed?

I have a data grid with a calendar column. 我有一个带有日历列的数据网格。 What I want to do is an event (not sure which one is suitable), and this is what should happen: 我想做的是一个事件(不确定哪个适合),这就是应该发生的情况:

  1. There should be a check to see if one of the row's dates were changed; 应该检查一下该行的日期是否已更改;
  2. If the value of one row has been changed (specifically the date column - which is also the only editable column), another method will execute (let's call it Update() ) - I already have the method figured out. 如果一个行的值已经改变(具体日期列-这也是唯一可编辑的列),另一种方法将执行(姑且称之为Update() -我已经有方法想通了。 I just don't know how to do the whole check to see if a value has been changed. 我只是不知道如何进行整个检查,以查看值是否已更改。

CellValueChanged doesn't work as it is triggered if anything changed on the grid, such as loading the data etc. Is there something else I can use? 如果在网格上进行了任何更改(如加载数据等), CellValueChanged都不会触发,因为它会被触发。还有其他可以使用的东西吗?

Let me know if I need to add more info, I'm not quite sure how to do this. 让我知道是否需要添加更多信息,但我不确定如何执行此操作。

    private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
    {
        DataGridViewColumn column = dataGridView1.Columns[e.ColumnIndex];
        if (column.Name == "dateColumn")
        {
            UpdateStuff();
        }
    }

    private void UpdateStuff()
    {
        object myDate = dataGridView1.CurrentCell.Value;
    }
 private void dgvResults_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        var selectedColumn = this.dgvResults.Columns[e.ColumnIndex];
        var vm = (PurchaseOrdersTrackingViewModel) this.dgvResults.Rows[e.RowIndex].DataBoundItem;

        if (selectedColumn.Name == this.colDueDate.Name)
        {
            this.SingleDueDate = Convert.ToDateTime(this.dgvResults.Rows[e.RowIndex].Cells[this.colDueDate.Index].Value);

            if (!this._mapicsWorkday.IsWorkDay(this.SingleDueDate.Date))
            {
                this.ShowMessage("Due date selected must be a valid working day.");
                return;
            }
            if (this.SingleDueDate.Date < DateTime.Today)
            {
                this.ShowMessage("You cannot set a past date as a due date.");
                return;
            }

            vm.HasCommentUpdateApplied = true;
            this.UpdateSingleOrder = true;
            this._presenter.BulkUpdateItems();
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM