473,804 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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("Fir stName")
dc2 = New DataColumn("Las tName")
dc3 = New DataColumn("Age ")

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

ds.Tables.Add(d t)
DataGrid1.DataS ource = 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.FormatEx ception "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 4418

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

Similar topics

5
2275
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 DataGrid? I've found a number of postings and help topics but would like to find something that treats the DataGrid as a topic, not just a loose collection of hundreds of articles. TIA,
1
2916
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 textboxes. The datagrid and textboxes are populated from the same underlying SQL Server table but using different strongly typed data adapters and datasets for display and editing. So I coordinate syncronization of the two sets of data using code. I use...
1
3015
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 I want to perform the validation only on the datagrid rows where a check box is checked. Part of the datagrid: <asp:TemplateColumn HeaderText="C #"> <ItemTemplate>
3
3002
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 fields that require validation. No problem, I put the validators on them and they work just fine... Except for the fact that when a user has an invalid entry and fires a validation event client side the scroll position is reset to the top of the...
5
3248
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 I use an argument to difference between an 'edit' vs. and 'add. But since I have field validation on both 'footer' and 'edit' columns I can't submit my edits since the footer validation kicks in.If I take the validation off then the both work fine...
4
3484
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 Edit Commmand are getting fired properly. The One difference I have seen is that in the task bar ..on hovering on the link the javascript for the update link seems different. I dont know if it makes sense..
4
2978
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 linkbuttons which must not cause validation. I have found a setting "causeValidation" to disable the validation. Also on the page, I have a datagrid that I will edit lines on. I can click
5
2056
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 time property of causevalidation. How can I keep them from causing validation? Thanks, T
0
1054
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 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.
0
10562
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10303
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,...
1
7608
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
6845
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
5508
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
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2978
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.