Problems with Data Grid

sfmejia

New member
Joined
Jun 8, 2004
Messages
3
Programming Experience
Beginner
Hi,
I have a Datagrid in my application, and one of the columns is pretended to be an automatic field (incremented by one), but my problem is that I don't know how to identify when the user is adding a new row, and how to set a value (max + 1) to that column if it's a new row,
I'm working with Visual Basic .net,

I'll really appreciate if someone can help me,
 
Usually, you would let the database do the autoincrement by setting the field to autonumber (syntax is for Access DB, may differ for other types). You don't specify a value for the autonumber field and the database determines the next required number.

Specify the type of database you're using and you may get more specific help. :)
 
Thanks for the answer,

I'm using ORACLE 6i.

I'll explain with more detail my problem:

I have a datagrid named grdDepartment, with 3 gridColumns: DataGridTextBoxColumn1 (ID_DIVISION), DataGridTextBoxColumn2 (ID_DEPT) and DataGridTextBoxColumn3 (NAME_DEPARTMENT).

I want the application to increment by one the ID_DEPT field, so, as you said, I used the autoincrement property for the dataset, this way:

objDependencia.Tables(1).Columns(0).AutoIncrement = True
objDependencia.Tables(1).Columns(0).AutoIncrementSeed = 1
objDependencia.Tables(1).Columns(0).AutoIncrementStep = 1

but now I have this problem:

The ID_DEPT depends on the ID_DIVISION, because every DIVISION has a group of DEPTS. If we have this values:

ID_DIVISION = 1

and for DIVISION 1 in the Datagrid:
ID_DEPT = 1
ID_DEPT = 2
ID_DEPT = 3

and ID_DIVISION = 2

in the Datagrid:
ID_DEPT = 1

First the application sets the ID on 4 (that is ok) in the first DIVISION, but in the second group set 4 either, when the rigth value is 2,

What is left to do ?
 
thank you very much.
You lead me on the right direction to solve my problem,
The increment works correctly now,

For those who may have similar problems, what I did was to increment the field in the "Navigation" event handler (an object -button- that let the user load the next set of data in the datagrid), with this code:

objDivision.Tables(1).Columns(0).DefaultValue = f.generate_id("department", "id_department", "where id_division=" & editid_division.Text

where f.generate_id is a user defined class, and objDivision is a Dataset,


and that was it !
 
Back
Top