C# winformdatagrid  ... Col1  Col2 ...
      12    0当在Col2中录入值时,如果其值比对应Col1的值大,则提示,且焦点停留在该Col2中,等待用户的其他输入。

解决方案 »

  1.   

    这个问题说来复杂了....
    你要做的好这个事情,要从DataGridColumnStyle或直接从DataGridTextBoxColumn继承一个新的列类型,然后重写Commit方法以达到在编辑单元格的时候对用户输入的值精确的处理.
    不是一两句代码就写的好的.如果要是没有要求那么高,那么可以在DataGrid.CurrentCellChanged 事件 来处理这个事情.
      

  2.   

    thanks.
    我要在哪个方法中处理如果录入的值不合理,焦点就停留在该Cell中?
    请赐教。
      

  3.   

    举个例子,CurrentCellChanged事件
    private void Handle_CurrentCellChanged(object sender, System.EventArgs e)
    {
    newCurrentRow = dataGrid1.CurrentCell.RowNumber;
    newCurrentCol = dataGrid1.CurrentCell.ColumnNumber;
    string newText = dataGrid1[oldCurrentRow, oldCurrentCol].ToString();
    if( !IsValidValue(oldCurrentRow, oldCurrentCol, newText))
    {
    MessageBox.Show("Entry Error");
    dataGrid1.CurrentCell = new DataGridCell(oldCurrentRow, oldCurrentCol); }
    oldCurrentRow = newCurrentRow;
    oldCurrentCol = newCurrentCol;
    }
      

  4.   

    IsValidValue函数就可以判断这个col2的值的关系了。应该可以实现