473,799 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reposting : DataGridView leaves an empty row after escape pressed onnew row

Hello,

I have a datagridview bound to a database table with 2 columns. One is an ID column "NameID" which is hidden, the other is called "Name".

The schema picture is here : http://img89.imageshack.us/img89/1251/dbschemaep9.jpg

What happens is :
1. Form loads with values from database inside the DGV
2. I press the checkbox to enable editing/adding etc in the grid (see code event)

Picture : http://img145.imageshack.us/img145/8819/step1yy3.jpg

3good. I click inside the NewRow and type "a" or whatever (something invalid) ...

Picture : http://img80.imageshack.us/img80/1923/step2cl5.jpg

4good. and press escape ... the row is deleted! (Just as I want it)

But... alternatively

3bad. I click inside the NewRow and type "a" or whatever (something invalid), then click outside the DGV on the checkbox or the button, the DGV still keeps focus as "a" fails validation and forces the DGV to keep focus, an error icon is also shown as normal

Picture : http://img80.imageshack.us/img80/1923/step2cl5.jpg
Picture : http://img89.imageshack.us/img89/4729/step3jl5.jpg

4bad. THEN I press escape ... and there is an empty row left! I have no idea why this happens as the focus never left the DGV (as far as I know) so I dont see why the behaviour is different.

Picture : http://img89.imageshack.us/img89/8317/step4yg5.jpg

=============== ===

Please if anyone knows what Im doing wrong, let me know, I havent been able to figure out why it does this for over a day.

=============== ===

CODE :

Imports System.Text.Reg ularExpressions

Public Class frmNames

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'TODO: This line of code loads data into the 'SampleDbDataSe t.Names' table. You can move, or remove it, as needed.
Me.NamesTableAd apter.Fill(Me.S ampleDbDataSet. Names)
End Sub

Private Sub dgvNames_CellEn dEdit(ByVal sender As Object, ByVal e As System.Windows. Forms.DataGridV iewCellEventArg s) Handles dgvNames.CellEn dEdit
' Remove the error icon (valid input or escape pressed)
dgvNames.Rows(e .RowIndex).Erro rText = String.Empty
End Sub

Private Sub dgvNames_CellVa lidated(ByVal sender As Object, ByVal e As System.Windows. Forms.DataGridV iewCellEventArg s) Handles dgvNames.CellVa lidated
' Get reference to current datarow
Dim CurrentDataRow As SampleDbDataSet .NamesRow = DirectCast(Name sBindingSource. Current, DataRowView).Ro w

' Update current row
If CurrentDataRow. RowState <DataRowState.U nchanged Then
NamesTableAdapt er.Update(Curre ntDataRow)
End If
End Sub

Private Sub dgvNames_CellVa lidating(ByVal sender As Object, ByVal e As System.Windows. Forms.DataGridV iewCellValidati ngEventArgs) Handles dgvNames.CellVa lidating
' Don't validate an empty row
If dgvNames.Rows(e .RowIndex).IsNe wRow Then Exit Sub

' Check the name against a pattern
If Regex.IsMatch(e .FormattedValue , "^[A-Z]\. [A-Z][a-z]+['-]?[a-z]+$") = False Then
dgvNames.Rows(e .RowIndex).Erro rText = "The name is invalid, it should be something like A. Mohammed"
e.Cancel = True
End If
End Sub

Private Sub chkEdit_Checked Changed(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles chkEdit.Checked Changed
' Enable or disable the grid for editing
With dgvNames
.ColumnHeadersV isible = chkEdit.Checked
.RowHeadersVisi ble = chkEdit.Checked
.AllowUserToAdd Rows = chkEdit.Checked
.AllowUserToDel eteRows = chkEdit.Checked
.ReadOnly = Not chkEdit.Checked
End With
End Sub

Private Sub btnClose_Click( ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnClose.Click
' Close the form
Me.Close()
End Sub
End Class

--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-

Jul 28 '06 #1
0 1303

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
7428
by: Binny V A | last post by:
Hello Everyone, I am new to python and I am trying to get a program to close a application when the Escape Key is pressed. This is the code that I used --------------------------------- from Tkinter import *
21
1510
by: John Welch | last post by:
Sometimes I post a question here and someone answers it quickly with an answer like "well, I don't know much about this, but maybe such and such." While I completely appreciate their effort, I might not get the answer I need because then everyone else sees the thread as answered and leaves it alone, and it drops down toward the bottom of the list. Is it ok to repost the question in this situation? Or is there some way to mark a question as...
0
1113
by: YiFai | last post by:
Hello, I'm currently writing a directx program with C++, but it takes a while to load the files necessary for the directx. When the directx window loads, it can quit the program with the 'escape' key by using the keydown events provided by directx libraries. What I would like to do is be able to quit the program before it finishes loading if the user presses the 'escape' key during the load. I will use a boolean variable to determine...
16
3344
by: sudhir | last post by:
hi how to check escape key is pressed when accepting the string as input. Because I do not want to receive a string if user presses the ESCAPE key.. I used ascii code for comparision but I didn't get any fruitful results. Please help me.
0
6949
by: TNSFED | last post by:
I have a dilemma when trying to delete a row from the DataGridView. Here is a sample of my code: private void dgv_EQUPS_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { fDeleteRow = false; if (chx_DeleteFlag.Checked) {
1
3756
by: David | last post by:
I have a realtime stock quote system developed where I am updating a typed dataset with realtime quotes. I want my DataGridView control to show green forecolor when a price moves up and red forecolor when a price moves down. I am using the cellvaluechanged event of the DataGridView control and thought it would be fired when the Dataset(the DataGridView's datasource) is updated. CellValueChanged is not fired when the dataset is updated. ...
1
7790
by: George | last post by:
Hi, Does anyone know how to simulate the 'escape' key functionality for cancelling add ing a new row in DataGridView. I have attempted to use CancelEdit(). They seem to only remove/dispose the editing of the current cell of the added row. However, the new row is still there. One way I can think of is <below>, but I think it is somewhat ugly. Any
0
9099
by: Asif Mohammed | last post by:
Hello, I have a datagridview bound to a database table with 2 columns. One is an ID column "NameID" which is hidden, the other is called "Name". The schema picture is here : http://img89.imageshack.us/img89/1251/dbschemaep9.jpg What happens is : 1. Form loads with values from database inside the DGV 2. I press the checkbox to enable editing/adding etc in the grid (see code event)
3
5257
by: hzgt9b | last post by:
Using VS2005, VB.NET, I am developing a windows app that has a DataGridView. I want to enable the display of a context menu on this DataGridView only when a specific set of keys is also pressed (like CTRL+ALT+SHIFT). TO this point I have code that only displays the context menu while keys CTRL +ALT+SHIFT are pressed - but after the keys are released the context menu still gets displayed. Can someone tell me where the following code is...
0
9689
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10248
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10032
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7573
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5469
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5597
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2942
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.