Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF
Hey all,
 
In my WPF application I have a datagrid and now I want to get the value of a cell.
I have tried dozens of possible solutions but none of them are working.
 
Can you guys help me out?
 
Greetz, A
Posted 6-Jul-11 22:22pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This discussion[^] could help you out.
  Permalink  
Comments
Alex Bouma at 7-Jul-11 3:53am
   
Im struggling with the VisualChild class where can I find that?
Espen Harlinn at 7-Jul-11 14:19pm
   
My 5
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Alex Bouma at 7-Jul-11 3:46am
   
Im struggling with the VisualChild class where can I find that?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Colin Eberhardt did a nice article on the WPF datagrid WPF DataGrid Practical Examples[^] - I would certainly look at databinding before working directly with the cells.
 
Best regards
Espen Harlinn
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Hi,
I've been struggling on this one too.
 
You can try this (it works for me):
 
Dim drv As System.Data.DataRowView = CType(Me.myDataGrid.SelectedItem, System.Data.DataRowView)
MsgBox(drv.Item(0).ToString())
 
Works fine even with Option Strict On, hope it helps!
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Try following helper function
 
public static DataGridCell GetCell(DataGrid dataGrid, int row, int column)
        {
            DataGridRow rowContainer = GetRow(dataGrid, row);
            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
                    dataGrid.ScrollIntoView(rowContainer, dataGrid.Columns[column]);
 
                    cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(column);
                }
 
                return cell;
            }
 
            return null;
}</datagridcellspresenter>
 
You can search more from Vincent SDibal's blog
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web01 | 2.8.150326.1 | Last Updated 5 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100