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 5980853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:51:38+00:00 2026-05-22T21:51:38+00:00

In Silverlight, how does one get row data from a DataGrid that is full

  • 0

In Silverlight, how does one get row data from a DataGrid that is full of data?

I have gotten this far (in a method that receives a button click on a row(:

DataGridRow item = (DataGridRow)dg.SelectedItem;

Now, how do I get the individual components of the item that I guess is the selected row?

Help me out here. How do you bind an observablecollection to the grid?

How do you use the cast system when you cast to the object?

When I read the data into the grid, I used this class:

public class Data
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public int Age { get; set; }
    public bool Available { get; set; }
    public int index_1 { get; set; }
    public int index_2 { get; set; }
    public int index_3 { get; set; }
    public int index_4 { get; set; }
    public int index_5 { get; set; }
    public int index_6 { get; set; }
    public int index_7 { get; set; }
    public int index_8 { get; set; }
    public int index_9 { get; set; }
    public int index_10 { get; set; }
    public int index_11 { get; set; }
    public int index_12 { get; set; }
    public int index_13 { get; set; }
    public int index_14 { get; set; }
    public int index_15 { get; set; }
}

So how so I cast when I read back out

This does not work:

Data _mydata = new Data();  
YValue = (_mydata.index_1)dg.SelectedItem;

This does not work:

YValue = (index_1)dg.SelectedItem;

This does not work:

YValue = (Data().index_1)dg.SelectedItem;
  • 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-22T21:51:38+00:00Added an answer on May 22, 2026 at 9:51 pm

    If you have bound a ObservableCollection<Foo> to your grid, your selected item can just be cast into your object – (Foo)dg.SelectedItem

    EDIT– UPDATE TO ANSWER UPDATED QUESTION

    The simple answer is, if you are not using MVVM (which I assume by your post your not), in the code behind create a collection (preferably ObservableCollection) of Data and set the grids itemsource property to your collection

    public ObservableCollection<Data> MyCollection{get;set;}
    
    void SetGridItemsSource()
    {
    // populate your collection here, then use the below line to associate it with your
    // grids itemssource      
    MyGrid.ItemsSource = MyCollection;
    
    }
    
    public void GetSelectedItem()
    {
       //Simply cast the selected item to your type
       Data selectedItem = (Data)MyGrid.SelectedItem;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Withing a Silverlight Application, how does one get the ID from the URL when
Does any one where we can get SharpZipLib implementation in Silverlight 4.0
I have a Silverlight 4 application that I want to secure. Does Silverlight 4
How does one start development in Silverlight? Does one need a new IDE? or
Since silverlight does not have any support for DataSets/DataTables, what would be the best
I'm using the Silverlight UnitTest framerwork does anyone have a good example have how
I'm struggling to understand Dependency Properties in Silverlight 2. Does anybody have a good
I couldn't get this to work in Silverlight, so I created two test projects.
Im just starting to get to grips with silverlight 3, coming from ASP.NET and
I've been looking for a ContextMenu control for Silverlight. There is one from Microsoft,

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.