Delete datagridview row using right click context menu does not behave like the delete key

I have a datagridview with editing enabled. If I click the row header and press the delete key, the row is removed no questions asked. I don't recall doing any coding to make this happen but I couldn't do copy and paste using keys so I created a context
menu with copy, paste, & delete.  The delete option calls
dgvVX130.Rows.RemoveAt(dgvVX130.SelectedRows[0].Index);
The row is removed but the problem is this fires other events like RowValidating which fails.  I presume because the row is no longer there.
The delete keypress is definitely a lot cleaner so my question is 3fold. 
1) Why doesn't Rows.RemoveAt behave like the delete key? 
2) Is it possible to issue a delete keypress to do the same thing?
3)  Is it possible to suppress the RowValidating event or other events when Rows.RemoveAt is fired?

Interesting.  My delete key does not fire the row validating event.  When I use the delete key I click on the row header which does fire the row validating event and then I press the delete key.  Row is deleted and no event fires.  Works
just the way I want it to.  I wish my context menu delete worked that way.  I wouldn't know what chunk of code I can provide to show the Row Validating NOT firing when delete key is pressed but here is the context menu code that does fire Row Validating.
private void cmsEditItemClick(object sender, ToolStripItemClickedEventArgs e)
ToolStripItem item = e.ClickedItem;
switch (item.Text)
case "Copy":
if (dgvVX130.GetCellCount(DataGridViewElementStates.Selected) > 0)
try
// Add the selection to the clipboard.
Clipboard.SetDataObject(
dgvVX130.GetClipboardContent());
// Replace the text box contents with the clipboard text.
catch (System.Runtime.InteropServices.ExternalException)
MessageBox.Show("The Clipboard could not be accessed. Please try again.");
break;
case "Paste":
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
ClipboardUtils.PasteFromClipboard(dgvVX130);
dgvVX130.NotifyCurrentCellDirty(true);
dgvVX130.EndEdit();
dgvVX130.NotifyCurrentCellDirty(false);
bindingSource1_PositionChanged(this, e);
break;
case "Delete":
dgvVX130.Rows.RemoveAt(dgvVX130.SelectedRows[0].Index);
break;
default:
//code
break;
private void dgvVX130CellContentClick(object sender, DataGridViewCellEventArgs e)
//dgvVX130.IsUserSelectionEnabled = true;
dgvVX130.BeginEdit(false);
((TextBox)dgvVX130.EditingControl).SelectionStart = 0;
//((TextBox)dgvVX130.EditingControl).SelectionLength = 3;
public class ClipboardUtils
public static void PasteFromClipboard(DataGridView grid)
try
char[] rowSplitter = { '\r', '\n' };
char[] columnSplitter = { '\t' };
// Get the text from Clipboard
IDataObject dataInClipboard = Clipboard.GetDataObject();
string stringInClipboard = (string)dataInClipboard.GetData(DataFormats.StringFormat);
// split into rows
string[] rowInClipboard = stringInClipboard.Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries);
// get current cell
int currentRow = grid.SelectedCells[0].RowIndex;
int currentColumn = grid.SelectedCells[0].ColumnIndex;
// get 1st cell in selected area
for (int i = 1; i < grid.SelectedCells.Count; i++)
if (currentRow > grid.SelectedCells[i].RowIndex)
currentRow = grid.SelectedCells[i].RowIndex;
if (currentColumn > grid.SelectedCells[i].ColumnIndex)
currentColumn = grid.SelectedCells[i].ColumnIndex;
// add more rows if need to paste data
/* if (grid.Rows.Count < rowInClipboard.Length + currentRow)
grid.Rows.Add(rowInClipboard.Length + currentRow - grid.Rows.Count); */
// paste
for (int iRow = 0; iRow < rowInClipboard.Length; iRow++)
if (iRow + currentRow < grid.Rows.Count)
string[] cellsInRow = rowInClipboard[iRow].Split(columnSplitter);
for (int iCol = 0; iCol < cellsInRow.Length; iCol++)
if (grid.ColumnCount > currentColumn + iCol)
DataGridViewCell currentCell = grid.Rows[currentRow + iRow].Cells[currentColumn + iCol];
if (!currentCell.ReadOnly) // H.NH added to avoid Read only case.
if (cellsInRow[iCol] == "")
if (grid.Columns[iCol].ValueType.Name == "String")
currentCell.Value = null;
else
currentCell.Value = DBNull.Value;
else
currentCell.Value = cellsInRow[iCol];
switch (iCol)
case 3:
currentCell.Value += "_ChangeColumnName";
break;
case 2:
currentCell.Value = grid.Rows[iRow].Cells[iCol].Value;
break;
else break;
catch (Exception e)
MessageBox.Show("Sorry, can not paste from the clipboard.\nError: " + e.Message, "Paste Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

Similar Messages

  • Right click context menu does not appear only for Java 1.7, AWT TextField

    I have been debugging some issues that an application has been having with Java 1.7 versus older versions. A new problem I have encountered is that the right click context menu does not function in any TextField. It works fine when running/compiling it with any previous version of Java. I have tried coding a simple test with a Frame, Panel and TextField to see if it might be something else in the more complex application that was causing it, but the simple test class has the same problem.
    I have searched for other people having the same issue, but I have not found anything comparable. This seems like a huge change from one version to the next and I am surprised that I am not finding this mentioned anywhere else. Can someone point me to anything that discusses this issue that I am having? Does 1.7 require I implement my own context menu? I realize AWT is old technology, but this is an old, fairly complex application that doesn't use swing, and that is not going to change at this point.
    My simple test:
    import java.awt.*; 
    import java.awt.event.*; 
    import java.util.*; 
    class testF3 extends Panel 
      public static void main(String args[]) 
        Frame f = new Frame(); 
        Panel p = new Panel(); 
        f.setLayout(new BorderLayout()); 
        f.add("North", p); 
        TextField tf1 = new TextField("", 20); 
        p.add(tf1); 
        Dimension medm = f.getSize(); 
        medm.height = 100; 
        medm.width = 200; 
        f.setSize(medm); 
        f.setVisible(true); 

    In the past few days since upgrading to 4.0.4, the entire right-click context menu for links is gone and replaced with one item: "Copy Link" The "Open In New Tab" item, along with some other context items, is no longer there.
    That's actually a problem with your particular installation of Safari, b. I've got all the contextual menu entries with my 4.0.4.
    I helped fix one of these recently here at the forum. Try the procedure from the following post (it got back Tho's missing contextual menu entries):
    http://discussions.apple.com/thread.jspa?messageID=10598385&#10598385

  • "Save link as" in Right-click Context menu is not working properly.

    Firefox 17: In a Google search, when I right click on a .pdf link, the popup window automatically gives a "url" filename and "Firefox Document" as filetype. Previously, the filename would be whatever it was on the website (ie. "filename.pdf") and the filetype would be "Adobe Acrobat Document".
    I know this problem has less to do with Firefox and more to do with JavaScript, because the problem disappears if you disable JavaScript (Tools -- Options -- Content -- uncheck "Enable JavaScript"). What's happening is that JavaScript is somehow altering the link from a purely .pdf link to something else -- perhaps encasing the link inside a set of commands, and the computer is trying to save the command string instead of recognizing the link for what it is. When JavaScript is disabled in Google searches, the highlighted "[PDF]" link no longer appears in front of the link itself, and the "Save link as" function on the right-click works properly.
    Any JavaScript junkies want to try their hand at creating a workaround? One that ensures that the reference created by the right-click context menu matches exactly what the filename is for the website?

    The problem is that Google has an onmousedown attribute added to the links that modify a link if you click or right-click a result link to make the link point to a safe browsing check on the Google server.<br />
    You can see that if you hover a link and you will notice that after you have (right) click a link the the URL changes to www.google.com/url?xxxxx.
    You can use this bookmarklet to remove the onmousedown attributes.
    <pre><nowiki>javascript:(function(){var e=document.querySelectorAll('*[id="search"] a[onmousedown]'),E,i;for(i=0;E=e[i];i++){E.removeAttribute('onmousedown')}})()</nowiki></pre>

  • Right click context menu is not working in flash player 10 and above

    In right click custom context menu i have create like "A" if i click "A" i have attached one movie clip in that movie clip right click, i have custom context menu like "Remove A" this is working fine in flash player 9 and below. But flash player 10 and above fisrt "A" is working fine but in that movieclip clip right click "Remove A" is not working Please guide me regarding this issue.
    Thanks in Advance
    Surendran S

    The problem is that Google has an onmousedown attribute added to the links that modify a link if you click or right-click a result link to make the link point to a safe browsing check on the Google server.<br />
    You can see that if you hover a link and you will notice that after you have (right) click a link the the URL changes to www.google.com/url?xxxxx.
    You can use this bookmarklet to remove the onmousedown attributes.
    <pre><nowiki>javascript:(function(){var e=document.querySelectorAll('*[id="search"] a[onmousedown]'),E,i;for(i=0;E=e[i];i++){E.removeAttribute('onmousedown')}})()</nowiki></pre>

  • Is it possible to add a button to the right-click context menu for a user in Outlook 2010 using VBA?

    I've tried many things and read up quite a bit but I cannot figure this out.
    I cannot create an add-in so I have to use VBA.
    I want to add a a button to the right-click context menu when I right-click on a user. Is this possible?

    Hello,
    Yes, it is possible to customize the context menu in Outlook. See
    Customizing Context Menus in Office 2010 for more information.
    But VBA doesn't allow to customize the Fluent UI in Outlook, you need to develop an add-in instead.

  • 1) (Right click) Context menu is IE's context menu(!) and when I attempt to use a sight that uses scripts (a site that I've used extensively and which I use to conduct my online college courses - application is Angel), it goes blank

    1) (Right click) Context menu is IE's context menu(!) and (2)when I attempt to use a sight that uses scripts (a site that I've used extensively and which I use to conduct my online college courses - application is Angel), it goes blank
    == This happened ==
    Every time Firefox opened
    == 2 days ago ==
    == User Agent ==
    Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; WWTClient2; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; Creative AutoUpdate v1.10.10)

    Previous post from "Not Anonymous" but from the original poster; I used the link provided in the email notification and now have to indicate who I am???
    Thanks; starting FireFox in safe mode and disabling all add-ons did solve the problem; however, a new problem has emerged. To re-enable the add-ons, you need to open up and use the add-ons control panel through FireFox. Any attempt to do so causes the FireFox add-on control page to close immediately.
    Thanks for your help.

  • Is there any way to prevent the right click context menu from combining Stop/Reload?

    Is there any way (about:config tweak, or something) to prevent the right click context menu from combining Stop/Reload?
    Screenshot of what I'm talking about: http://picsend.net/images/873089StupidReloadSto.png

    I did try the add-on ''Menu Editor'' https://addons.mozilla.org/en-US/firefox/addon/menu-editor/ but even when I separate the navigation reload and stop icons and explicitly have both stop and reload set to be visible on the right click context menu I only get the one option showing.
    Whilst there may be some way of changing this I do not know how to and I do not really see any use case for making such a change. Only one option of the choice: stop or reload, is available at any instance in time, but that is the option you are able to use, the other option is not active and so is not displayed.

  • Update for RDP 8.1 Windows 7 SP1 changed explorer right click context menu

    I have a 4 pcs and 3 nas drive on my network.  previous to the update I could view my pcs and nas drives in explorers right pane left click one and access the folders on it.  since the update I can no longer do this because "remotedesktopconnection"
    has been added as the default (previously it was "open") to the right click context menu.  can someone help me change this back so when I right click a network computer icon in explorer I only see:
    open                                                                   
    AND NOT                              remotedesktop
    open in a new window                                                                                       open
    create shortcut                                                                                                 open
    in a new window
                                                                                                                           create
    shortcut
    the exact update that makes the change is: kb2592687

    Hi
    Theoretically it could be done by modify registry. For example you could
    modify right click menu on .exe file by changing values under
    HKEY_CLASSES_ROOT\exefile\shellex\
    However there are some problems that I cannot define that what kind of “file”
    the network computer is.
    And I found no article specific to this.
    If you really need to restore your context menu and also need this update, I
    suggest you uninstall this update first. Then back up your registry, install it
    again. This time using process monitor you could record all registry modifications during
    this update installation. It might take lots of work.
    I tried to do that for you, unfortunately this update has been deployed in our environment which cannot be uninstalled from update history.
    For more information about process monitor
    https://technet.microsoft.com/en-us/library/bb896645.aspx?f=255&MSPPError=-2147217396
    Regards
    D. Wu
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact [email protected]

  • Disable Right Click Context Menu in XP "OPEN WITH ADOBE READER 8"

    How can I eliminate the right click context menu "OPEN WITH ADOBE READER 8" in Windows XP?
    I have general familiarity with removing context menus. I see no option for this one in msconfig, or various context menu editors. I am unable to find a setting in Adobe Reader 8. If you know where the setting is, or have solved this problem, please let me know.
    Thanks,
    Joey

    That would be the device Metadata from the print driver vendor. It's part of the Device Stage feature mainly for client OS.
    Here is some MSDN documentation on the feature.
    http://windows.microsoft.com/en-us/windows7/products/features/device-management
    If this is a print server, use the tools include by the print team if you are performing any management on the server.
    Printmanagement.msc
    The Devices UI is really about devices it's not designed for print management, the spooler team had minimal input on the UI design.
    Alan Morris formerly with Windows Printing Team

  • How do I modify the file right-click context menu to add "creat shortcut"?

    I have just chosen Mozilla as my browser and want to add shortcuts to files by using the right-click context menu, but there is no "create shortcut" choice displayed.

    Could you describe where you're clicking, exactly? Are you clicking on a web page, or clicking a link on a web page? If you are using Firefox to browse files on your hard drive, you're probably better off using Windows Explorer to do that since Firefox doesn't have all the functions of Windows.

  • T40's Left Shift key makes right click/context menu appear?

    Hello All-
    On my T40, on which I just recently got Windows 7 correctly installed, has a curious behavior:
    When I press the left shift key, it functions the same as if I had pressed the right mouse button.  It functions correctly otherwise, I.E., when using it to capitolize a letter in an email, the letter is capitolized, but as soon as I let go of the shift key, the right click/context menu immediately appears.
    This is exceedingly irritating, as I cannot continue typing until I have navigated out of the menu.
    I have checked to see if the Keyboard Customiser utility is causing this, as I currently have my left Alt key functioning as a Windows button, but it does not appear to be causing this particular issue.
    Does anyone have any idea how I might go about fixing this?
    Thanks in advance,
    G
    Solved!
    Go to Solution.

    Nevermind-
    Had the keyboard customizer set to use the left shfit key as the application key.  Duh.

  • Right-Click context menu is gone

    Using Windows 7, Safari 4.0.4. I noticed recently that when I right-click on a link, I saw the link context menu and I used to be able to select "Open in new tab" This was great to use the mouse only to navigate, open new tabs, and surf around...using just the mouse.
    In the past few days since upgrading to 4.0.4, the entire right-click context menu for links is gone and replaced with one item: "Copy Link" The "Open In New Tab" item, along with some other context items, is no longer there.
    To be honest, this is pretty useless. If I'm only using the mouse, then this means that I have to:
    1. Right Click on a link, select Copy Link
    2. Right click in the tab bar and select "New Tab"
    3. Click in the address bar of the new tab to select the field
    4. Right-click in the address bar and select paste
    5. And now I'm still having to use the keyboard to submit the address as there is no "Go" button for the address bar.
    I know I can just Ctrl + Click a link to open in a new tab, but that requires the keyboard and the mouse.
    I'm all for simple interfaces, but why did you take away the link's right-click context menu? It made surfing and opening tabs so easy using just the mouse.

    In the past few days since upgrading to 4.0.4, the entire right-click context menu for links is gone and replaced with one item: "Copy Link" The "Open In New Tab" item, along with some other context items, is no longer there.
    That's actually a problem with your particular installation of Safari, b. I've got all the contextual menu entries with my 4.0.4.
    I helped fix one of these recently here at the forum. Try the procedure from the following post (it got back Tho's missing contextual menu entries):
    http://discussions.apple.com/thread.jspa?messageID=10598385&#10598385

  • Satellite M100 - Right click context menu kepps popping up

    The right click context menu keeps popping up in my Toshiba Satelite M100 thereby making it so hard to type.
    I disabled my touch pad and used a mouse but still the menu keeps popping up. What should I do? How do I know whether my touchpad driver is installed correctly? Also how to reinstall it?
    Please give step by step instruction because when I tried to install, I get the message error in installing ikernel.exe...
    Please help

    Hi,
    I know I sound stupid but I have some questions regarding uninstalling the existing version. I have Toshiba touchpad driver and toshiba touchpad ON/Off utility.
    Should uninstall both? Also i disabled the touchpad using the the ON/OFF utility and used a mouse but still the menu kept popping up.
    This problem occurs most of the time. At times,everything works fine for a few hours and then the problem starts. I scan my computer for viruses once in a week and updates my antivirus daily. Also I had my computer formatted after this problem started. Still this prob occurs.
    Please help.

  • Libreoffice right-click context menu going beyond the end of the page

    having a rather annoying issue with libreoffice 3.x (started with 3.5.x and still in 3.6.1): The right-click context menu goes over the screen borders when I am at the end of the page (instead of opening in the other direction so that all options are visible). I am running arch 64bit KDE 4.9.1. But I think in this case that's not relevant because we have a second computer, the same one basically with an extremely similar setup and there it works just fine. I did uninstall libreoffice, got rid of the .cache in the home folder, then reinstalled but the problem persists.
    Anyone know how to fix this or hints on how to approach the problem?
    Thx!
    Captn

    Update:
    the problem was fixed with an update to KDE 4.9.2 but shortly after for some reason, it reappeared. As previously mentioned, I tried uninstalling libreoffice entirely, including the libreoffice .config folder. Here is what it looks like (second screen shot):
    I noticed that this also happens with dolphin when I open it as root. Someone came across the same issue and fixed it?
    Help's greatly appreciated
    Captn
    Edit: libreoffice version 3.6.1
    Edit 2: Real Problem identified:
    I just wanted to update this thread should there be others that, at one point or another, run into a similar problem. I won't be marking the thread as solved since I did not actually solve the problem (yet). However, I did identify the cause and therefore know how to circumvent it.
    Since I didn't elaborate much on the specs / technical side, I have an HP pavilion with an Nvidia card and I am using the propretiary drivers. I set up a separate X screen for my TV and there is where the problem lies. It has worked for months but since recently this setup causes some weird graphical behavior (as in the above pictures) which can be annoying. If using the twinview setup or no external monitor, everything works normal. My guess is that plasma-desktop and the separate x screen don't work very well together for a reason unknown to me for the time being.
    The problem itself can be annoying if you rely on libreoffice to work so I hope this might help somebody should there be annyone running into a similar issue.
    Last edited by capthilts (2012-10-13 06:02:32)

  • Right click context menu super slow!!!

    i have window 8.1 64bit when i try to right click mouse it take a really long time(like 1 or 2 minute) to response, and
    this is for all office(word, ppt) files, chrome, and some music files.
    I have already tried the way recommended by this website:
    http://windowsxp.mvps.org/slowrightclick.htm
    but it doesn't work,
    Can anyone help me???

    Hi,
    For the issue, I suggest we try the clean boot mode and safe mode to test if we can get rid of this problem.
    How to perform a clean boot to troubleshoot a problem in Windows 8.1, Windows 8, Windows 7, or Windows Vista
    http://support.microsoft.com/kb/929135
    Meanwhile, please let us try SFC tool to check the result:
    Use the System File Checker tool to repair missing or corrupted system files
    http://support.microsoft.com/kb/929833
    In addition, you can also refer to the similar thread about this issue:
    http://social.technet.microsoft.com/Forums/windows/en-US/84875a10-663a-40b8-aac8-87d64473b0b6/right-click-context-menu-slow?forum=w7itproperf
    Let we test if it also apply to Windows 8.
    Regards,
    Kelvin hsu
    TechNet Community Support

Maybe you are looking for

  • Itunes uses 100% cpu

    There has been a great deal of discussion and comment about Itunes consuming 100% of CPU on my windows laptop. I have seen various solutions but have to say none of them actually work for me. I have disabled the Apple exe for itunes startup but of co

  • Color Management Issues Solved in LR 1.1?

    Long tempted to switch from Elements 5.0 to LR (or to integrate the two), I have held off because I've read on this forum dozens, probably hundreds, of complaints about LR 1.0 and color management. Some of these questions were clearly from ignorance,

  • The great DVD media question (again prolly?)

    Hi, iMac g5 rev b with Matshita uj-845 I have 20 photo slideshows to burn off for a friends sons christening and want reliable media that will: 1. Burn 8x 2. Offer the best compatablity for stand alone players 3. Offer best price/quality balance UK b

  • Export Raw Files and keep XMP data

    Hi, I can export files from Lightroom to a folder and select original and I will get the raw file along with the xmp file. I therefore have any adjustments I made there with it. If I , however , export files to a folder and select original and chose

  • Annotations - error in Sun Tutorial?

    In the Q&E section of The Sun Tutorial on Annotataions (http://java.sun.com/docs/books/tutorial/java/javaOO/QandE/annotations-answers.html), it says, Question 2: Compile this program: interface Closable { void close(); class File implements Closable