Solved

Duplicate rows in TDB8.0

Posted on 2004-04-02
4
487 Views
Last Modified: 2007-12-19
Hi experts,

I am using TDBGrid 8.0 and VB6.
My grid is unbound, using an XArrayDB.

When a new row (row1) gets save/updated (when then user click on another row, the addnew row, row2)
The row1 gets duplicated on the grid (NOT in the database). The record appears twice on the grid (on the row1 as it should, AND on the first row, the one on top of all rows).

Does anybody has an idea why ?
Thanks

gallia
0
Comment
Question by:Gallia
  • 2
  • 2
4 Comments
 
LVL 39

Expert Comment

by:appari
ID: 10745211

can you post the code related to where you are initializing the xarray (xarray.redim) and filling with initial data etc.
0
 

Author Comment

by:Gallia
ID: 10765696
Hi appari,

Sorry for the delay, I was away. Here is the code.

    Set objArray = New XArrayDB

    If o_rsData.EOF Then
        objArray.ReDim 0, 0, 0, 0
        o_objGrid.SetNbColumn 0
        'Bind the XArrayDB structure with Grid
        Set o_objGrid.Grid.Array = objArray
        Set o_rsData = Nothing
        Exit Sub
    Else
        objArray.ReDim 0, o_rsData.RecordCount - 1, 0, o_rsData.Fields.Count - 1
        o_objGrid.SetNbColumn o_rsData.Fields.Count
    End If

    'Display titles on column header
    With o_objGrid.Grid.Columns
        For i = LBound(i_vListInfo) To UBound(i_vListInfo)
            .Item(i).ValueItems.Presentation = i_vListInfo(i).Presentation
            If i_vListInfo(i).CaptionID <> 0 Then
                .Item(i).Caption = LoadResString(i_vListInfo(i).CaptionID)
            Else
                .Item(i).Caption = i_vListInfo(i).SystemName
            End If
            .Item(i).Tag = i
            .Item(i).Locked = i_vListInfo(i).Locked
            .Item(i).Width = i_vListInfo(i).DefaultWidth
            If i_vListInfo(i).Format = "" Then
                o_objGrid.SetColFormatADO i, i_vListInfo(i).DataType
            Else
                o_objGrid.SetColFormat i, i_vListInfo(i).Format
                o_objGrid.SetColAlignment i, i_vListInfo(i).Alignment
            End If
            .Item(i).Visible = i_vListInfo(i).Visible
        Next i
    End With

    If Not o_rsData.EOF Then
        'Populate XArrayDB structure
        i = 0
        With o_rsData
            While Not .EOF
                For j = 0 To objArray.Count(2) - 1
                    objArray(i, j) = .Fields(j).Value
                Next j

                .MoveNext
                i = i + 1
            Wend
        End With
    End If

    'Bind the XArrayDB structure with Grid
    Set o_objGrid.Grid.Array = objArray

    'Find the ADO data type of current column
    eADODataType = adVarChar

    o_objGrid.SetColAlignment 0, vbCenter
    o_objGrid.ApplyFormat

    Enabled = True
0
 
LVL 39

Accepted Solution

by:
appari earned 150 total points
ID: 10765963
change this part

   If o_rsData.EOF Then
        objArray.ReDim 0, 0, 0, 0
        o_objGrid.SetNbColumn 0
        'Bind the XArrayDB structure with Grid
        Set o_objGrid.Grid.Array = objArray
        Set o_rsData = Nothing
        Exit Sub
    Else
        objArray.ReDim 0, o_rsData.RecordCount - 1, 0, o_rsData.Fields.Count - 1
        o_objGrid.SetNbColumn o_rsData.Fields.Count
    End If


to


   If o_rsData.EOF Then
        objArray.ReDim 0, -1, 0, o_rsData.Fields.Count - 1

        o_objGrid.SetNbColumn 0
        'Bind the XArrayDB structure with Grid
        Set o_objGrid.Grid.Array = objArray
        Set o_rsData = Nothing
        Exit Sub
    Else
        objArray.ReDim 0, o_rsData.RecordCount - 1, 0, o_rsData.Fields.Count - 1
        o_objGrid.SetNbColumn o_rsData.Fields.Count
    End If


when no data is found always set rows ubound to -1. columns to no of columns in the grid. its working fine on my m/c.

is SetNbColumn is your own method?

0
 

Author Comment

by:Gallia
ID: 10766301
Thanks it worked.

SetNbColumn is my own. It is used for all the grid (tdbg) in the application.

gallia
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now