Drag the winform datagridview & WPF DataGrid (Drag & Drop)

Source: Internet
Author: User
Tags wpf datagrid

Download source-117kb

As shown in the preceding two figures, the left side is the winform datagridview and the right side is the WPF DataGrid (encapsulated as the custom control dragdatagrid and loaded in winform through the WPF elementhost ). You can drag and drop the rows to sort them. In addition, you can drag data from the winform datagridview to the WPF DataGrid. Therefore, the drag and drop methods between two dview are similar to those between two DataGrid. The above controls disable the sort function and set the allowdrop attribute to true.

  • Drag and Drop rows in winform dview

    • Use the drag & Drop Series Method to pass the pulled row data through E. Data. getdata (). The movement of tippanel is controlled in mousemove.
  • Row dragging of the WPF DataGrid
    • Click here to use the method on a foreigner's blog
  • Drag between the datagridview and DataGrid
    • The following code reports a com exception in the dragenter method of the WPF DataGrid:
    • 1 DataGridViewRow curRow = (DataGridViewRow)e.Data.GetData(typeof(DataGridViewRow));

      Therefore, a data serialization class dataserializer is encapsulated to serialize the databounditem of the drag-and-drop row of the current dview to the string type. In WPF, use the following code to obtain the string and then deserialize it as an instance object.

    • string strRow = (string)e.Data.GetData(DataFormats.StringFormat);
      Animal aimAnimal = (Animal)DataSerializer.DeserializeObject(strRow);
  • Tipcontrol & popup
    • In winform, A tipcontrol usercontrol is used to display the row information during the Drag and Drop Process.
    • Use popup in WPF to display the current row Information
  • Press ctrl and drag the row to assign a value to the data row.
  • Problems: there are still some bugs and deficiencies. You can learn from them for reference only.

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.