473,398 Members | 2,335 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,398 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 4386

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
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...

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.