Get cell value from Silverlight DataGrid sample – (Video)

1. Add button name btnCell.

2. Add code to button click event.

String strID = ((TextBlock)dataGrid1.CurrentColumn.GetCellContent(dataGrid1.SelectedItem)).Text;

 

Watch the video below.

 

Get cell value from Silverlight DataGrid sample – (Video) part 1

 

3. Add code

lblCell.Content = strID;

 

4. Add Label name lblCell.

 

Watch the video below.

 

Get cell value from Silverlight DataGrid sample – (Video) part 2

 

Key takeaway:

The code that direct cast from FrameElement to text

String strID = ((TextBlock)dataGrid1.CurrentColumn.GetCellContent(dataGrid1.SelectedItem)).Text;

 

Download the complete code from http://skydrive.live.com. The sample file name is SilverlightAppDataGridBind1.rar. My MSN ID is chanmmn@hotmail.com.

 

Resources:

Bind List to Silverlight DataGrid sample – (Video)

Silverlight WCF RIA Domain Service Class – CRUD (Part1 Create Domain Service Class)

Silverlight WCF RIA Domain Service Class – CRUD (Part2 Create Entity – Row)

Silverlight WCF RIA Domain Service Class – CRUD (Part3 Read Entity – Row)

Silverlight WCF RIA Domain Service Class – CRUD (Part4 Update Entity – Row)

Silverlight WCF RIA Domain Service Class – CRUD (Part 5 Delete Entity – Row)

http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.selecteditem(v=vs.95).aspx

 

Advertisements

About chanmingman

Since March 2011 Microsoft Live Spaces migrated to Wordpress (http://www.pcworld.com/article/206455/Microsoft_Live_Spaces_Moves_to_WordPress_An_FAQ.html) till now, I have is over 1 million viewers. This blog is about more than 50% telling you how to resolve error messages, especial for Microsoft products. The blog also has a lot of guidance teaching you how to get stated certain Microsoft technologies. The blog also uses as a help to keep my memory. The blog is never meant to give people consulting services or silver bullet solutions. It is a contribution to the community. Thanks for your support over the years. Ming Man is Microsoft MVP since year 2006. He is a software development manager for a multinational company. With 25 years of experience in the IT field, he has developed system using Clipper, COBOL, VB5, VB6, VB.NET, Java and C #. He has been using Visual Studio (.NET) since the Beta back in year 2000. He and the team have developed many projects using .NET platform such as SCM, and HR based applications. He is familiar with the N-Tier design of business application and is also an expert with database experience in MS SQL, Oracle and AS 400.
This entry was posted in .Net and tagged . Bookmark the permalink.

7 Responses to Get cell value from Silverlight DataGrid sample – (Video)

  1. Mayur says:

    TextBlock txtBlock=(TextBlock) myGrid.Columns[1].GetCellContent(myGrid.SelectedItem);

    Try This…

  2. ramjie lee says:

    how to get the value of a specific cell from datagrid? Can you show me some code behind?

    Thanks,,m

    • chanmingman says:

      I have checked SilverlightAppDataGridBind1.rar is still in my skydrive. Can you download it from there?

      • ramjie lee says:

        I can’t see any link where I could download SilverlightAppDataGridBind1.rar. in your post.
        Sir, What I would like to do is the value of a specific cell will be selected OnLoad. Without any mouse event involve. ex I would like to get the cell content of column[1] row[1]
        HERES MY SAMPLE DATA:(Not real world data)
        city population
        philippines 10,000,000
        China 100,000,000

        result = 100,000,000

        I have browse many sites already cant find any of them matches my problem, Most of them has a mouse event.
        Thanks sir. 🙂

  3. chanmingman says:

    i have downloaded the rar and email to you.

    • ramjie lee says:

      Thank you sir. Yes I received the sample codes and run it. But What I would like to do is I don’t need to use a boolean field. Instead the value or content of that row will be selected. Here’s my sample code snippet which is actually not working. It returns null.

      string cellcontent = Datagrid1.columns[1].getcellcontent( //this should be a row count integer DataGridRow //).toString();

      I could get the column cell but I couldn’t get the row cell. If I could get the row cell, then I could get the specific content of that cell.This will be done Onload as well.
      Do you have any Idea how to get the row cell sir?

      Thank you sir. 🙂

  4. Sunil R says:

    Hello Everyone, I am also facing the same issue i can get the Column but its difficult to get row. To get the particular cell value you should need both column and row index. can anyone help me out. here is my code.

    cw.Study_ID = Study_dataGrid.Columns[0].GetCellContent( /* row index of selected row */).ToString();

    I have to do this event on Mouse enter, so please do not prefer row selected event.

    Thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s