Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WPF
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 11-Feb-13 1:28am
jiji26631.7K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Let's assume we have data grid like this:
<DataGrid Name="DataGrid1" SelectionMode="Single"
          SelectionChanged="DataGrid1_SelectionChanged">
</DataGrid>
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[^].
  Permalink  
Rate this: bad
good
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.
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web02 | 2.8.141022.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
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