Solved

TDBGRID

Posted on 2009-07-07
10
1,893 Views
Last Modified: 2013-12-26
How can I Insert a row in tdbgrid?
example : I have 5 rows that had encoded already then i want to insert 1(one)  row between 2 and 3 rows.
I'm using this
tg.InsertMode but it dosn't work.
0
Comment
Question by:Whing Dela Cruz
  • 5
  • 4
10 Comments
 
LVL 4

Expert Comment

by:vbgb
ID: 24821255
If you are using the grid in 'Storage' mode with an XArrayDB object to store the data, you use the XArrayDB.InsertRows method to insert new rows.

If you are using it in 'Application' mode and the grid is tied to a VB array, you need to redim the array to insert a new value.

In both cases you then need to use the Rebind method on the grid to refresh the display.

0
 

Author Comment

by:Whing Dela Cruz
ID: 24835638
Hi! I am using XArrayDB object . Can you give me example on how to use xArray.insertRows? I'm trying many times but still didn't work!
Thanks!
0
 
LVL 4

Expert Comment

by:vbgb
ID: 24835974
Hi


Assuming you have a grid called 'Tbdgrid1' which is bound to an XarrayDB object called 'xa', the attached snippets should work. The first adds a new row at row 'lrowposition' and inserts values into the first 3 columns.

The second inserts 3 new rows at row 'lrowposition' and leaves them blank.

The Insertrows method returns the no. of rows added.

Remember to call Tdbgrid1.ReBind after modifying the xArray|Db object, to update the rows shown in the grid.


 'First snippet
  
   With xa
        .InsertRows lrowposition
        .VALUE(lrowposition, 1) = "New"
        .VALUE(lrowpositionw, 2) = "Data"
        .VALUE(lrowposition, 3) = "in the row0
    End With
    
    TDBGrid1.ReBind
 
'Second snippet
 
result=xa.insertrows lnewposition,3
'result should be 3

Open in new window

0
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 4

Accepted Solution

by:
vbgb earned 500 total points
ID: 24835980
I have corrected a couple of typos in the snippets!!
'First snippet
  
   With xa
        .InsertRows lrowposition
        .VALUE(lrowposition, 1) = "New"
        .VALUE(lrowposition, 2) = "Data"
        .VALUE(lrowposition, 3) = "in the row"
    End With
    
    TDBGrid1.ReBind
 
'Second snippet
 
result=xa.InsertRows lrowposition,3
'result should be 3
 

Open in new window

0
 

Author Comment

by:Whing Dela Cruz
ID: 24836010
Hi!  I will try it now but it needs a long time for me to make this trial since i am not good enough in vb6... Thank you so much for your help. I will give you an information any results.. Thanks!
0
 

Author Comment

by:Whing Dela Cruz
ID: 24854289
Hi! I'm very sorry but I was not able to get the correct Idea. Can you give some example? I attached the code below I hope you will give me some example base on my code. Thanks!  
Dim x As XArrayDB
Dim DB As New ADODB.Connection
Private Sub Form_Load()
INITG
End Sub
 
Private Sub INITG()
Dim MAXROW As Long, MAXCOL As Long
Set x = New XArrayDB
x.ReDim 0, 0, 0, 10
    For MAXROW = x.LowerBound(1) To x.UpperBound(1)
        For MAXCOL = x.LowerBound(2) To x.UpperBound(2)
            x(MAXROW, MAXCOL) = " "
        Next MAXCOL
    Next MAXROW
With tg
    .Close
'''    .Columns(0).Alignment = 3
'''    .Columns(1).Alignment = 3
'''    .Columns(2).Alignment = 1
'''    .Columns(3).Alignment = 1
'''
'''    .Columns(0).Locked = True
'''    .Columns(2).Locked = False
'''    .Columns(0).Width = 1900
'''    .Columns(1).Width = 3500
'''    .Columns(2).Width = 1500
'''    .Columns(3).Width = 1500
'''     .Columns(3).Locked = True
'''     .Columns(4).Locked = True
'''    .Columns(1).AutoDropDown = True
    .Array = x
End With
End Sub

Open in new window

0
 
LVL 4

Expert Comment

by:vbgb
ID: 24855363
I have added some more code and comments to yours - hopefully this explains how to add and fill rows in the array and then rebind the grid to display them.
Dim x As XArrayDB
Dim DB As New ADODB.Connection
Private Sub Form_Load()
INITG
End Sub
 
Private Sub INITG()
Dim MAXROW As Long, MAXCOL As Long
Set x = New XArrayDB
 
' Here you are setting up the array with 1 row and 11 columns,
' which are all filled with a space.
x.ReDim 0, 0, 0, 10
    For MAXROW = x.LowerBound(1) To x.UpperBound(1)
        For MAXCOL = x.LowerBound(2) To x.UpperBound(2)
            x(MAXROW, MAXCOL) = " "
        Next MAXCOL
    Next MAXROW
With tg
    .Close
'''    .Columns(0).Alignment = 3
'''    .Columns(1).Alignment = 3
'''    .Columns(2).Alignment = 1
'''    .Columns(3).Alignment = 1
'''
'''    .Columns(0).Locked = True
'''    .Columns(2).Locked = False
'''    .Columns(0).Width = 1900
'''    .Columns(1).Width = 3500
'''    .Columns(2).Width = 1500
'''    .Columns(3).Width = 1500
'''     .Columns(3).Locked = True
'''     .Columns(4).Locked = True
'''    .Columns(1).AutoDropDown = True
 
' Here you assigning the array as the datasource for the grid
    .Array = x
 
' Now we need to put some data in the array using the AppendRows or InsertRows methods
' You will perhaps do this by reading from a database table
        .InsertRows 0,3               'this inserts 3 rows before the blank row that you already have
        .VALUE(0, 0) = "New"
        .VALUE(0, 1) = "Data"
        .VALUE(0, 2) = "in the first row"
        '.. continue until all columns are filled
        .VALUE(1, 0) = "Some More"
        .VALUE(1, 1) = "Data"
        .VALUE(1, 2) = "in the second row"
        '.. continue until all columns are filled
        .VALUE(2, 0) = "Some More"
        .VALUE(2, 1) = "Data"
        .VALUE(2, 2) = "in the third row"
        '.. continue until all columns are filled
 
' Finally you need to rebind the grid to the new values in the array    
    TDBGrid1.ReBind
 
' The grid should now appear with data 3 rows of data and a blank row at the end.
 
End With
End Sub

Open in new window

0
 

Author Comment

by:Whing Dela Cruz
ID: 24855721
Thanks! I will try it now...
0
 

Author Closing Comment

by:Whing Dela Cruz
ID: 31600528
Thanks!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Paint/Redraw window while dragging 16 79
String manipulation in Visual Basic 7 66
VB 6 error 5 in windows 10 but not in XP 7 57
Sub or Function is not defined 6 31
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

831 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