Skip to content

Ultragrid copy paste issue

New Discussion
Jyoti Salve
Jyoti Salve asked on May 27, 2022 1:17 PM

When i copy any text and paste it into the ultragrid cell ,it is directly replacing the existing cell value.It is not pasting where the cursor location is.

It means suppose in ultragrid cell value is “XYZ” and i paste ABC in between Y and Z then it is direclty replacing XYZ with ABC .I want like “YABCZ” because i put the cursor in between Y and Z so my value should be pasted in between this but it is direclty replacing whole value.

Please suggest me asap

Sign In to post a reply

Replies

  • 0
    Michael DiFilippo
    Michael DiFilippo answered on May 25, 2022 2:18 PM

    Hello and thank you for reaching out. I closed the other post to continue with this one. Please check the Form1.Designer.cs file, as I used the designer to wire up the grid to a datasource. No additional settings are required to achieve the behavior you desire. If you can’t replicate the issue with the sample and it works as intended please modify and reattach it here so I can take a look at why the copy and paste behavior isn’t working as expected. Let me know if you have any questions.

     

    • 0
      Jyoti Salve
      Jyoti Salve answered on May 25, 2022 4:11 PM

      Thanks for the reply

      Actually i want to give support of both context menu and control keys to copy paste the value.

      our customer dont want to use existing bydefault cut/copy/paste option which are already in the edit box on right click thats why we have added context menu for these operation.

      So for this i used PerformAction method but it is replacing whole word as i described earlier

      so  i removed PerformAction  from the code now it is working bydefault for control events (ctrl+c,ctrl+v) but then it is not working for context menu.

      I have also set AllowMultiCellOperations to copy and paste

      Do you have any sample program for this context menu and control events copy paste value in grid cell.

      Thanks in advance

      • 0
        Michael DiFilippo
        Michael DiFilippo answered on May 25, 2022 7:04 PM

        Please clarify as I am a little confused what you've implemented. Did you provide a context menu for when the cell is not in edit mode or in edit mode or both? 

        I believe its best if you can replicate the behavior with my sample so I can take a look. If the cursor position is set in the cell during edit mode I would expect the paste to function as expected without any additional code even if a custom context menu was applied. 

      • 0
        Jyoti Salve
        Jyoti Salve answered on May 26, 2022 10:33 AM

        Please find attached sample where i create context menu so using context menu copy paste is replacing whole value without remembering cursor position. Please suggest what i am doing wrong here

        Attachments:
      • 0
        Michael DiFilippo
        Michael DiFilippo answered on May 26, 2022 4:45 PM

        Thank you for providing a sample. It' helped me realize that you need the clipboard operations on the TextBox, since that is what the cells are using. In edit mode you are no longer interacting with the grid itself. This was discussed here:

        https://es.infragistics.com/community/forums/f/ultimate-ui-for-windows-forms/23280/ultragrid-problems-with-cut-copy-paste-features

        To achieve your requirement, with a custom context menu, you cannot use the grid's PerformAction but rather the textbox operations which we expose like so:

        e.g

        ((TextBox)this.ultraGrid1.Controls[0]).Paste();

        public partial class Form1 : Form
        {
        ContextMenuStrip menu = new ContextMenuStrip();
        ToolStripMenuItem copy = new ToolStripMenuItem { Text = "Copy"};
        ToolStripMenuItem paste = new ToolStripMenuItem { Text = "Paste"};
        
        public Form1()
        {
        InitializeComponent();
        
        copy.Click += Copy_Click;
        paste.Click += Paste_Click;
        this.ultraGrid1.DisplayLayout.Override.AllowMultiCellOperations = AllowMultiCellOperation.All;
        
        ultraGrid1.ContextMenuStrip = this.menu;
        
        }
        
        private void Paste_Click(object sender, EventArgs e)
        {
        ((TextBox)this.ultraGrid1.Controls[0]).Paste();
        }
        
        private void Copy_Click(object sender, EventArgs e)
        {
        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false, false);
        
        ((TextBox)this.ultraGrid1.Controls[0]).Copy();
        }
        
        private void ultraGrid1_AfterEnterEditMode(object sender, EventArgs e)
        {
        menu.Items.Add(copy);
        menu.Items.Add(paste);
        }
        
        private void ultraGrid1_AfterExitEditMode(object sender, EventArgs e)
        {
        menu.Items.Clear();
        }
        }

      • 0
        Jyoti Salve
        Jyoti Salve answered on May 27, 2022 5:37 AM

        Perfect!! This is working fine. Thank you so much Michael.

      • 0
        Michael DiFilippo
        Michael DiFilippo answered on May 27, 2022 1:17 PM

        You are very welcome. Have a nice day. 

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Jyoti Salve
Favorites
0
Replies
7
Created On
May 27, 2022
Last Post
3 years, 9 months ago

Suggested Discussions

Tags

Created by

Created on

May 27, 2022 1:17 PM

Last activity on

Feb 24, 2026 12:11 PM