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.