We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

ExcelLike Sfdatagrid

hi

How to Achieve ExcelLikeFillSelection in SfDataGrid with red border and Cross Cursor?

This features is available in GridControl, but not in SfSatagrid


4 Replies

DM Dhanasekar Mohanraj Syncfusion Team March 13, 2023 01:49 PM UTC

Hi Ali,

We are a little unclear about your scenario, but we suspect that your requirement is to "Select multiple cells with dragging" which will be achievable by using the SelectionMode as Extended or Multiple and SelectionUnit as Cell has shown below,

Multiple SelectionMode:

<Syncfusion:SfDataGrid x:Name="dataGrid"               

                       AutoGenerateColumns="False"

                       SelectionMode="Multiple"

                       SelectionUnit="Cell"

                       ItemsSource="{Binding Orders}" />


Extended SelectionMode:

<Syncfusion:SfDataGrid x:Name="dataGrid"               

                       AutoGenerateColumns="False"

                       SelectionMode="Extended"

                       SelectionUnit="Cell"

                       ItemsSource="{Binding Orders}" />


If we misunderstood your requirement, please provide more information regarding it. If you need to update the selection only or change the Value while performing the DragSelection? Also, you have mentioned that the required behavior is also available in GridControl; could you please confirm whether you have mentioned an Excel-like selection frame If not, please share more information about this. It would help us to proceed further.


Regards,

Dhanasekar M.



AL ali March 13, 2023 10:28 PM UTC

thank you


Please see the video below
Can it be implement with SfDatagrid?

Attachment: 20230314_015425_a2073bc7.zip


DM Dhanasekar Mohanraj Syncfusion Team March 14, 2023 02:40 PM UTC

Ali,


We have checked the feasibility of achieving your requirement. Our SfDatagrid does not contain any direct support to achieve your requirement. However, you can copy one cell and paste it into the selected cell by creating the CustomGridCopyPaste in SfDataGrid. GridCopyPaste class has many overrides to customize copy and paste operations. To achieve the above, you can override the PasteToCells (object clipboardrows) shown below,

this.sfdatagrid.GridCopyPaste = new CustomCopyPaste(sfdatagrid);



public class CustomCopyPaste : GridCutCopyPaste

{

    public CustomCopyPaste(SfDataGrid sfgrid)

        : base(sfgrid)

    {

    }

    protected override void PasteToCells(object clipboardrows)

    {

        var data = (IList)clipboardrows;

        var firstrowdata = Regex.Split(data[0].ToString(), @"\t");

        //Gets the ClipboardText and checks when the clipboard text is more than one cell

        // calls the base.

        if (data.Count > 1 || firstrowdata.Count() > 1)

        {

            base.PasteToCells(clipboardrows);

            return;

        }

        //Gets the selected cells to paste the copied cell

        var selectedcells = this.dataGrid.GetSelectedCells();

        int selectedcellscount = selectedcells.Count;

        for (int i = 0; i < selectedcellscount; i++)

        {

            var record = selectedcells[i].RowData;

            var column = selectedcells[i].Column;

            //Calls PasteToCell method with particular record of selectedcells,

            // Column of selected records and rowdata

            PasteToCell(record, column, data[0]);

        }

    }

}


For more information related to customizing Copy/Paste behavior, please refer to the below user guide documentation link,

UG Link: https://help.syncfusion.com/wpf/datagrid/clipboard-operations#customizing-copy-paste-behavior-in-wpf-datagrid

Please find the sample in the attachment.

If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.



AL ali replied to Dhanasekar Mohanraj March 15, 2023 10:09 AM UTC

thank you


Loader.
Up arrow icon