Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 871031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:34:37+00:00 2026-05-15T10:34:37+00:00

I am trying to get a cell value from the selected item of a

  • 0

I am trying to get a cell value from the selected item of a silverlight datagrid. In the attached code I can get to the properties of the cell and change its forecolor, but I can not get the value of the cell. Can someone please let me know what I am doing wrong? Many thanks in advance for your help!

    private void FindDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        DataGrid dataGrid = sender as DataGrid;

        int selectedIndex = dataGrid.SelectedIndex;
        if (selectedIndex > -1)
        {
            FindResult findResult = (FindResult)FindDetailsDataGrid.SelectedItem;

            DataGridColumn column = dataGrid.Columns[0];
            FrameworkElement fe = column.GetCellContent(dataGrid.SelectedItem);
            FrameworkElement result = GetParent(fe, typeof(DataGridCell));

            if (result != null)
            {
                DataGridCell cell = (DataGridCell)result;
                //changes the forecolor
                cell.Foreground = new SolidColorBrush(Colors.Blue);
                //how to get cell value?
            }
        }
    }

    private FrameworkElement GetParent(FrameworkElement child, Type targetType)
    {
        object parent = child.Parent;
        if (parent != null)
        {
            if (parent.GetType() == targetType)
            {
                return (FrameworkElement)parent;
            }
            else
            {
                return GetParent((FrameworkElement)parent, targetType);
            }
        }
        return null;
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T10:34:37+00:00Added an answer on May 15, 2026 at 10:34 am

    Thanks VooDooChild, see below for my solution using the textblock to get at value.

    private void FindDetails_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataGrid dataGrid = sender as DataGrid;
    
            int selectedIndex = dataGrid.SelectedIndex;
            if (selectedIndex > -1)
            {
                FindResult findResult = (FindResult)FindDetailsDataGrid.SelectedItem;
    
                DataGridColumn column = dataGrid.Columns[0];
                FrameworkElement fe = column.GetCellContent(dataGrid.SelectedItem);
                FrameworkElement result = GetParent(fe, typeof(DataGridCell));
    
                if (result != null)
                {
                    DataGridCell cell = (DataGridCell)result;
                    //changes the forecolor
                    cell.Foreground = new SolidColorBrush(Colors.Blue);
                    //how to get cell value?
    
                    TextBlock block = fe as TextBlock;
                    if (block != null)
                    {
                        string cellText = block.Text;
                        MessageBox.Show(cellText);
                    }
                }
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a value from a cell in my datagrid, the code
Im trying figure out how I can change the value of a specific cell
I'm trying to set up Excel so that the cell's value that is selected
I'm trying to get the cell value of an edited cell in a gridview.
I'm trying to get value from Excel cells in this way: SpreadsheetDocument spreadSheetDocument =
I'm trying to get the value of a specific cell in a table in
I am trying to get my program to read a value from a particular
I'm trying to use the following JavaScript function to get a particular cell value
I'm working with 2 XML documents, and trying to get a value from one
I can't seem to find anything on how to get a cells' value from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.