2011-08-08 92 views

答えて

0

これは、我々はあなたがGridViewコントロールやデータグリッドを意味するか、特定のセルの値

Object obj = GetCell(3).Content; 
        string cellContent = String.Empty; 
        if (obj != null) 
        { 
         if (obj is TextBox) 
          cellContent = ((TextBox)(obj)).Text; 
         else 
          cellContent = ((TextBlock)(obj)).Text; 
         } 




private DataGridCell GetCell(int column) 
    { 
     DataGridRow rowContainer = GetRow(); 

     if (rowContainer != null) 
     { 
      DataGridCellsPresenter presenter = GetVisualChild<DataGridCellsPresenter>(rowContainer); 

      // Try to get the cell but it may possibly be virtualized. 
      DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column); 
      if (cell == null) 
      { 
       // Now try to bring into view and retreive the cell. 
       customDataGrid.UCdataGridView.ScrollIntoView(rowContainer, customDataGrid.UCdataGridView.Columns[column]); 
       cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column); 
      } 
      return cell; 
     } 
     return null; 
    } 
0

選択された行のリストを取得するには、これを試してみてください:this related questionから

IList rows = dg.SelectedItems; 

を。データグリッド、あなたはCurrentCell-プロパティを経由して取得することができ、列の場合

1

DataGridCellInfo cellInfo = dataGrid.CurrentCell; 
DataGridColumn column=cellInfo.Column; 
+0

は、CurrentCellという名前のプロパティは存在しません。 – Abhi

+0

@Abhishek:System.Windows.Controls.DataGridについて話していますか?それとも、System.Windows.Controls.Gridを意味しますか?これには選択機能はありません。それはレイアウトコンテナだけです。グリッドコントロールの正確なタイプ名を投稿できますか?多分私はあなたを助けることができます... – HCL

関連する問題