datagrid1.CurrentCell
datagrid1.CurrentRowIndex

解决方案 »

  1.   

    datagrid1.Select(datagrid1.CurrentCell.RowNumber);
    可以是一行選擇
      

  2.   

    以下只能在readonly的情况下使用.即不想改变datacell的值.
    重写DataGridTextBoxColumn, // MyTextBoxColumn
    protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
    {
         // Do nothing.
    }
    然后在datagrid中加入tablestyle, tablestyle中使用你自己写的MyTextBoxColumn
      

  3.   

    假如你需要修改cell的值的话,
    尝试以下代码
    在MyTextBoxColumn中
    protected override void Edit(System.Windows.Forms.CurrencyManager source, int rowNum, System.Drawing.Rectangle bounds, bool readOnly, string instantText, bool cellIsVisible)
    {
    base.Edit(source,rowNum, bounds, readOnly, instantText , cellIsVisible); DataGridCell cell = this.DataGridTableStyle.DataGrid.GetCurrentCellBounds();
    this.TextBox.Location = cell.Location;
    this.TextBox.Size = new Size( cell.Width, cell.Height );
    }
      

  4.   

    Sorry, 上面有个错误:
    System.Drawing.Rectangle cell = this.DataGridTableStyle.DataGrid.GetCurrentCellBounds();
    不是:
    DataGridCell cell = this.DataGridTableStyle.DataGrid.GetCurrentCellBounds();