473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

WinForms Datagrid Validation VB.NET

JR
Hello,

Does anyone know how you can prevent a row full of 'null' values from being
added to the datagrid when a user hits the delete key, deleting the word
(null) which represents the default value of 'null'?

Here's a simple way to reproduce this problem:
1) Add a datagrid to a winform
2) Put this code into the Form1_Load event and run it.

Dim dc1, dc2, dc3 As DataColumn
Dim ds As New DataSet
Dim dt As New DataTable

dc1 = New DataColumn("FirstName")
dc2 = New DataColumn("LastName")
dc3 = New DataColumn("Age")

dt.Columns.Add("FirstName")
dt.Columns.Add("LastName")
dt.Columns.Add("Age")

ds.Tables.Add(dt)
DataGrid1.DataSource = dt

3) Delete the first (null) from the first column, then click into the next
row.

As you should see, the first row is left waiting to be updated back to the
datasource with nulls and an empty string. I know that the grid considers
the empty string to be valid user input so it allows it.
However, the problem also occurs if the datagrid were bound to a dataset
that specified the Age column to be an integer (FYI - The dataset I actually
use is populated by a SQL Stored Procedure). Then if you delete the (null)
from the Age column OR type a non numeric character and then click to the
next row, the grid will again allow the row full of nulls to remain except
this time all the columns are nulls.

What seems to happen in the case when using a bound datagrid with an integer
column is what is specified as automatic validation:
http://msdn.microsoft.com/library/de...ridcontrol.asp

.... which results in a System.FormatException "Input string was not in a
correct format." error.

I would like to be able to prevent a null row from being added (and
remaining) to the datagrid.

The ways I've thought of trying to accomplish this are:
1) Validate the data entered when the user clicks out of the cell. I think
I would need to create my own class that derived from the DatagridTextBox
class and add an event handler to trap this?

2) Prevent certain keystrokes. But I still want to allow users to use the
delete and backspace keys when appropriate.

3) Iterate through the rows and columns of the datagrid to programatically
delete any rows that have been left with all nulls or empty strings.
However, this seems kind of sloppy and would probably be confusing to the
user.

Any ideas regarding this would be greatly appreciated!!!
Jul 27 '05 #1
0 4381

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

Similar topics

5
by: John Spiegel | last post by:
Hey all, I have contusions and I think a minor concussion after trying to find information on advanced WinForms DataGrid use. Does anyone know of a site / book that gets really in-depth on the...
1
by: GregM | last post by:
I have a read only datagrid that is designed to coordinate itself with textboxes. When the user clicks on a row in the datagrid, detailed data for that row is displayed for editing in the...
1
by: Stephan Bour | last post by:
Hi, I need to validate a text box in a datagrid nested inside a datalist. All I need is to validate that any text is entered in the textbox. However, a requiredfieldvalidator would not do because...
3
by: Ben | last post by:
Hi, I have a page with a datagrid that you have to scroll to see. I'm using the StrengthControls SmartScroller as recommended to maintain my scroll position. Anyway, inside the datagrid I have...
5
by: Chris | last post by:
Based upon some prevoius postings on what to do for adding a 'add' row to a datagrid I utilize the footer to create the 'add' row. The only issue is that I have it sharing the 'UpDate_Command' and...
4
by: siaj | last post by:
Hello All, If some one has faced a similar issue.. My datagrid Update command is not getting fired in fact it seems that the no event fires on clicking the update link. Although the cancel and the...
4
by: David Colliver | last post by:
Hi all, I am having a slight problem that hopefully, someone can help me fix. I have a form on a page. Many items on the form have validation controls attached. Also on this form are...
5
by: Tina | last post by:
the Edit, Update, Cancel, and Delete buttons in my datagrid are causing validation elsewhere on the page. I want to specify that these buttons should not cause validation but they have no design...
0
by: JR | last post by:
Hello, Does anyone know how you can prevent a row full of 'null' values from being added to the datagrid when a user hits the delete key, deleting the word (null) which represents the default...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.