DataGrid double-click the current row to obtain data

Source: Internet
Author: User

Question

1. in WPF, click DataGrid to obtain the row currently clicked (I tried to use DataGrid. selecteditem and DataGrid. currentitem, it seems none of them work) 
2. I implemented the mousedoubleclick event and planned to use the mouseleftbuttomup event to handle the click event. Is there a conflict? 
3. when implementing the DataGrid, I found that the DataGrid is not very stable, and there will always be one more empty row at the end, and because I set a row to select a column (similar to the checkbox), when I check the last row, new rows are always randomly added. How can we make the DataGrid stable? (My DataGrid does not need to be editable internally) 
4. Is there any built-in sorting method for the DataGrid?

Answer:

1. If the itemssource of your DataGrid is an object set rather than a able, you can use DataGrid. selecteditem as youclass to obtain it.

2. If you want to implement the double-click behavior of javasird, you can try the previewmousedoubleclick event.

The first problem is that you cannot directly use DataGrid. selectitem. The selected row you actually obtain is a datarowview. You can use the following method to obtain the data of the selected row and reference system. Io.

VaR A = This. exdatagrid. selectitem;

VaR B = A as datarowview;

B ["filedname"]. tostring (); you can directly convert the data.

 

The third question. Set autogeneratecolumns = "false.

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.