Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Sir,

I want to take data (a row in the datagrid) from DataGrid in WPF to TextBox. The DataGrid has taken the values from a table in the database (SQL Server).

I want to select a row in the DataGrid to TextBox when click on the particular row

I wrote the code as follows:
C#
private void branchdg_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    txtbranchcode.Text = branchdg.SelectedItem.ToString();
}

but it gives the output as System.Data.DataRowView to the TextBox.

It may be very simple, but pls help me

Advance thanks...
Posted
Updated 10-Feb-10 6:07am
v3

The datagrid should have a selection changed event, if you've set it to allow selection. This will tell you what row is selected.
 
Share this answer
 
The item IS a DataRowView, so that's what you get. You need instead to take the SelectedItem and grab the data from the columns inside it. I suggest in general that you should read a book on C#, so you'd understand what this result means, and consider reading MSDN to learn how to use objects and methods you've not used before.
 
Share this answer
 

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