Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More DataGridView questions

Status
Not open for further replies.

kimprogrammer

Programmer
Sep 15, 2008
160
CA
Hello
I have a couple more problems with my datagridview. Of course this could be an easier process.

First
I can enter data in a row but when i try to enter another row the first row disappears/blank out. Is there something in the properties window that has to be set to allow the user to enter more than one row?

Secondly
when I select save from the binding navigator that was automatically set up when I dragged the datafile over as a datagrid the data does not get saved. When I follow the code it gets to the if statement "Me._keyscan_payrollDataSet.HasChanges" but then goes to end if - so it must not think HasChanges has been set.


Here is the code
Private Function Save()
Dim Saved As Boolean
If Me._keyscan_payrollDataSet.HasChanges Then
Try
Dim HoursAdd() As DataRow = Me._keyscan_payrollDataSet.SwipeAccumulativeHours.Select("", "", DataViewRowState.Added)

For x As Integer = 0 To HoursAdd.GetUpperBound(0)
With HoursAdd(x)
.Item("SwipeID") = "44"
.Item("EmpNum") = cboEmployee.Text
.Item("PPDay") = cboPPStart.Text
.Item("InputType") = 3
.Item("SupReasonCode") = ""
.Item("Userid") = Environment.UserName
.Item("Timestamp") = Now
End With
Next x

Me.SwipeAccumulativeHoursTableAdapter.Update(HoursAdd)
Saved = True

Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

End If

Return Saved

End Function

Thanks for your help
 
I have a little more info. I think this might have to do with the database but am not sure how to get around it.

In my datagrid view I am only having the user enter a few of the fields. I have a couple other fields that I don't want them to enter and have the system generate them. But they are part of the key. So I think when I try and enter data in the datagrid because there is already data with that key it is stopping it because I havn't gotten into the save funtion yet to assign the rest of the fields/keys.
 
My file is
Keys:
SwipeID as integer (it's an autonum)
EmpNum as char
PPday as datetime
InputType as Char
SupReasonCode as Char

data: (just fyi)
Paycode
Amount
Comments
Userid
Timestamp

On the data grid I show only Paycode,PPday,Amount,Comments.
The input type determines whether a manager or payroll administrator entered the record. This screen is meant for for the payroll administrator to make any adjustments to what the manager entered. I am only giving her add permissions because I want a data trail of everything entered.

 
I see a couple issues.

#1. If you are using an Identity/Automnum column as part of your primary key, there is no reason to use any of those other columns as part of the primary key. The Identity column will always be unique. You can put an index on those other columns, but there is no need to make it part of the primary key in this case.

#2. If your DataTable has the AutoIncrement property set correctly on your DataTable's Identity column, then there is no need to try to set this value in code. Let .Net and the database take care of this. If it's set to AutoIncrement, and you show the column on the grid, you will see it increments by itself. If someone happens to add a record to the table manually which conflicts with the number that shows up in the grid when you're entering a new record, it is designed to adjust the auto generated number in your DataTable accordingly.
 
I removed the keys and only have the autonum column as a key. I removed the dataset from the project then re-added it to make sure everything was ok.

For the second point - I knew the autonum took care of itself, I copied this code from my timesheet entry where I needed to put something in the column for it to process and that the auto num then changed it. Not realizing I didn't need here. So I have removed it here.

But I am still getting the same problem. I have another form set up with a datagrid that works. I checked both to see if any properties were different - but they are the same.
 
More info - I added the swipeid into the datagrid so I could see it. When I entered the line its number was 286. after I tabbed off the number to the next blank line, the line I entered disappeared (as mentioned) But when I went to enter info into the next blank line the auto num gave it the number 287. So line 286 looks like it is missing.
 
I can't really think what it would be off the top of my head, especially since you have one grid working, and I didn't have any problems doing a test either.
 
I have a bit more information.

When I load the data I am bringing in data only for one employee into the dataset.
The last autonum for that employee is 285. When I add a new row the autonum says 286.
There is already another employee with 286 in the database - the next available number is 410.
So it seems to be autonumbering on the dataset and not the database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top