Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: WPF
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 2: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
0 OriginalGriff 645
1 Maciej Los 225
2 Abhinav S 171
3 Richard Deeming 160
4 Suvendu Shekhar Giri 159
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 9,135
2 Peter Leow 5,042
3 Kornfeld Eliyahu Peter 3,373
4 Maciej Los 2,581

Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 11 Feb 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