Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi
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

Let's assume we have data grid like this:
XML
<DataGrid Name="DataGrid1" SelectionMode="Single"
          SelectionChanged="DataGrid1_SelectionChanged">
</DataGrid>

and event handler in code behind (xaml.cs file):
C#
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[^].
 
Share this answer
 
If you want selected row in button click ,you can write the below code in button click

C#
Yourbusinessobject object= this.DataGrid1.SelectedItem as Yourbusinessobject ;


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

in datagrid.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900