DataRowView drv=(DataRowView)this.BindingContext[this.DataGrid.DataSource].Current
获取当前选中的行.

解决方案 »

  1.   

    我要的是当前选中的单元格。行没用,行不是有selected_item事件吗,不用上边的也行。
      

  2.   

    DataGrid_SelectedIndexChanged事件是针对行的,我想要一个针对单元格的
      

  3.   

    CurrentCell
    private void SetCellWithFocus(DataGrid myGrid)
     {
        // Set the current cell to cell1, row 1.
        myGrid.CurrentCell = new DataGridCell(1,1);
     }
     
     private void dataGrid1_GotFocus(object sender, EventArgs e)
     {
        Console.WriteLine(dataGrid1.CurrentCell.ColumnNumber + 
        " " + dataGrid1.CurrentCell.RowNumber);
     }
      

  4.   

    public static void DataGrid_MouseUp(...)
    {
      System.Windows.Forms.DataGrid.HitTestInfo myHitTest;

     myHitTest =((System.Windows.Forms.DataGrid) sender).HitTest(e.X,e.Y); //获取单击的位置
    if (myHitTest.Type == System.Windows.Forms.DataGrid.HitTestType.Cell)  //如果单据的是单元格
       DataGrid.CurrentCell=new DataGridCell(myHitText.Row,myHitTest.Column); 
    }
      

  5.   

    前提是WebForm,不是WinForm,快啊!!!
      

  6.   

    设置server端OnItemCommand事件handler
    其参数类型DataGridCommandEventArgs,包含
    item 代表被单击的DataGridItem元素
    CommandName  代表与被单击item相关联的命令名(在定义grid的column的时候可以指定)
    比如:
    定义<asp: BoundColumn HeaderText="test" CommandName="test" />
    在handler里面
    if (e.CommandName == "test")
    {
    //.........
    }
      

  7.   

    DDRinDOOL() 
    其参数类型DataGridCommandEventArgs,包含
    item 代表被单击的DataGridItem元素-----------我的理解是用这个确定行
    CommandName  代表与被单击item相关联的命令名(在定义grid的column的时候可以指定)---用这个确定列
    俩一块确定cell
    比较可行,我试试,谢谢,要有补充再贴啊
      

  8.   

    DataGrid有一个CurrentCell就是当前的选中的单位格了.