 |
 |

02-26-2005, 09:44 AM
|
|
Centurion
|
|
Join Date: Feb 2004
Location: Canada
Posts: 120
|
|
Datagrid, getting rid of a "null" row
|
When the user scroll to the bottom of my datagrid, it creates a new row with null values. The user can then enter a new row.
I have a problem when the user open a new row and the leaves that row without entering values. In my currency manager, when the user changes row, I update the database. I fire a dg.update and a sqlda.update.
I've got an exception that is raised (dg.update) when the row is left with null values: IndexOutOfRangeException.
How can I get rid of that null row before firing the dg.update ?
Thanks
|
|

02-26-2005, 05:02 PM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
|
Via the DataStyles object, you can assign various features to your dataGrid, including a .nulltext property. So, you can add an empty string instead, some other default value, and then, in the validating event, or when they leave the cell, you can trap this default value and act accordingly.
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|

02-28-2005, 05:11 AM
|
|
Centurion
|
|
Join Date: Feb 2004
Location: Canada
Posts: 120
|
|
Quote:
|
Originally Posted by MKoslof
Via the DataStyles object, you can assign various features to your dataGrid, including a .nulltext property. So, you can add an empty string instead, some other default value, and then, in the validating event, or when they leave the cell, you can trap this default value and act accordingly.
|
Actually, it's not what I'm trying to fix... :-) I was not clear initially, I rephrase. :-)
In the DG, if the user "opens" a new row but do not enter anything, that empty row remains there and when I fire the dg.Update, the Update fails complaining about a rowindex of of bound. I want to delete that empty row. How do I do that.
Thanks again for your time.
|
|

02-28-2005, 04:32 PM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
|
You want to delete the empty row before updating? Why not use the .HasChanges and .GetChanges method, if the bound dataTable has no changes, nothing will be fired.
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|

03-01-2005, 05:48 AM
|
|
Centurion
|
|
Join Date: Feb 2004
Location: Canada
Posts: 120
|
|
Quote:
|
Originally Posted by MKoslof
You want to delete the empty row before updating? Why not use the .HasChanges and .GetChanges method, if the bound dataTable has no changes, nothing will be fired.
|
The datasource of my dg is a table in a dataset.
In my case, when there is an empty row and I fire an dg.update, the aboved mentionned exception is raised.
The exception gets fired only when there is an empty row.
When the exception is fired, I have a big red X in place of a datagrid....
You mentionned the .HasChanged and .GetChanges.... but I'm using the .Update method only.... Is it either use the .Update and pray it's gonna work or do everything manually with the .HasChanged and .GetChanges ? :-)
|
|

03-01-2005, 05:16 PM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
Before firing your update, you should check if the DataTable haschanges. Basically your dataGrid is bound to a dataset which contains the table and schema of the intial query. So if the user has not added a value record, there is nothing to update
Code:
Dim changes As DataTable
changes = DirectCast(DataGrid1.DataSource, DataTable).GetChanges()
If (Not changes Is Nothing) Then
MessageBox.Show("User added something")
End If
Basically you populate a datagrid. Then in the validating event, when the user leaves the dataGrid if they have tried to update an existing field (added text to a cell) or click on the bottom row in order to add a new record, the messagebox (in this case) will display. If they do nothing, nothing happens. if you need to trap the last cell the user was on, you will have to track the current cell. Then, if .GetChanges returns true, check that row..if there are null values prompt the user and flag it, etc.
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|

03-03-2005, 01:22 PM
|
|
Centurion
|
|
Join Date: Feb 2004
Location: Canada
Posts: 120
|
|
|
Thanks, I'll try to put that in place over the weekend!
|
|

03-03-2005, 05:09 PM
|
 |
Cum Grano Salis
Retired Moderator * Guru *
|
|
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
|
|
|
Good luck, let us know if you have any more questions.
|
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|