Click here to Skip to main content
13,452,641 members (56,394 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i have a datagrid with some rows and culomns and button send in from
i want a select row in datagrid and send values of selected row to another form

how do this????????
plase F1F1F1F1F1F1F1
Posted 11-Feb-13 1:28am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Let's assume we have data grid like this:
<DataGrid Name="DataGrid1" SelectionMode="Single"


and event handler in code behind (xaml.cs file):
private void DataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
    var item = DataGrid1.SelectedItem/* as YourBusinessObject*/;

    if (item != null)
        // Your code here

You should cast selected item to type of your business object.
If you are using anonymous types, you can use combination of the Selector.SelectedValuePath Property[^] and Selector.SelectedValue Property[^].
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If you want selected row in button click ,you can write the below code in button click

Yourbusinessobject object= this.DataGrid1.SelectedItem as Yourbusinessobject ;

and in xaml code put
SelectionMode="Single" and SelectionUnit="FullRow" 

in datagrid.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.180318.3 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2018
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