The WPF DataGrid obtains the value of a column in the selected row.

Source: Internet
Author: User
Tags wpf datagrid

[Go] the WPF DataGrid gets the value of a column in the selected row.

Method 1:
DataRowView mySelectedElement = (DataRowView) dataGrid1.SelectedItem;
String result = mySelectedElement. Row [0] ToString ();

Method 2:
Var a = this. dataGrid1.SelectedItem;
Var B = a as DataRowView;
String result = B. Row [0]. ToString ();


The wpf datagrid is bound to data. How can I obtain the value of a column in the selected row from multiple selected rows?

DataRowView selectItem = explorird. SelectItem as DataRowView;

Object obj = selectItem ["columnName"] or selectItem [index];

How does one obtain the value of the currently selected row in the WPF DataGrid?

DataGrid1.SelectedItem is the data entity object represented by the row selected by your dataGrid
You can obtain and set attributes of this object in the following ways:
(DataGrid1.SelectedItem as object). Attribute
I don't quite understand what textbox you are referring. By default, data in the table can be modified on the foreground. If you want to change the bound data source, you only need to set two-way binding.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.