Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DBGrid, Column reset when Refresh

Posted on 1998-12-13
5
Medium Priority
?
383 Views
Last Modified: 2012-05-04
When i use Refresh to update the contents of the grid
it resets the sizes of the columns and visibility properties to default ones which isn't very useful.
Is there something i can do to stop the resizing after i have initially set them?
Thanks
0
Comment
Question by:SIMONBRATT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:trkcorp
ID: 1449804
Is it a bound grid? If so, refreshing the data control rather than the grid itself should leave set attributes intact.
0
 
LVL 4

Expert Comment

by:CraigLazar
ID: 1449805
Hi Simon
I used this code for a grid control in vb3 and it works perfectly
u might have to modify it slightly. it refreshes when ever a new record is added to the database .
    On Error GoTo eh2:
 
    Dim rstab As Table
    Dim rsgrid As Table
    Dim i As Integer
    Dim numrec As Integer
    Dim tempnum As Integer
   
    Set rstab = DB.OpenTable("log")
   
    rstab.MoveLast
   
    rstab.MoveLast ' Count the records.
    grid2.Rows = rstab.RecordCount + 1 ' Set the rows.

    tempnum = rstab.RecordCount + 1
   
    grid2.Cols = rstab.Fields.Count + 1    ' Set the columns.
    grid2.SelStartCol = 1
    grid2.SelEndCol = grid2.Cols - 1
    grid2.SelStartRow = 1
    grid2.SelEndRow = grid2.Rows - 1

    grid2.Row = 0
    grid2.Cols = 7
    grid2.Col = 0
    grid2.ColWidth(0) = 1

    grid2.Col = 1
    grid2.ColWidth(1) = 1000
    grid2.Text = "Number"
   
    grid2.Col = 2
    grid2.ColWidth(2) = 1500
    grid2.Text = "Date"
   
    grid2.Col = 3
    grid2.ColWidth(3) = 1000
    grid2.Text = "Start"
   
    grid2.Col = 4
    grid2.ColWidth(4) = 1000
    grid2.Text = "End"
   
    grid2.Col = 5
    grid2.ColWidth(5) = 1800
    grid2.Text = "Dial Option"
   
    grid2.Col = 6
    grid2.ColWidth(6) = 2300
    grid2.Text = "Result"

rstab.MoveLast
    Do Until rstab.BOF ' Loop through the Snapshot.
        numrec = numrec + 1
        If numrec >= 150 Then
            Exit Do
        End If
        On Error Resume Next
        'grid1.Row = 1
          grid2.Row = grid2.Row + 1
        For i = 1 To grid2.Cols - 1 ' Cycle through the columns.
            grid2.Col = i   ' Set the column number.
         If i = 0 Then   ' If first column...
                grid2.Text = i  ' Set the value.
            Else
                grid2.Text = rstab(i)
            End If
        Next i
        On Error GoTo 0
        rstab.MovePrevious ' Move to next record.
        'grid1.Row = grid1.Row + 1  ' ' Set the row number.
    Loop
grid2.HighLight = False
rstab.Close
eh2:
  Exit Sub
End Sub


hope it helps
C

0
 

Author Comment

by:SIMONBRATT
ID: 1449806
it is a bound grid and i am refreshing the data control when it happens, if i use dbgrid.refresh it doesn't actually refresh the grid? eh?
0
 

Author Comment

by:SIMONBRATT
ID: 1449807
too complicated for a beginner, when does the grid get visibly updated?
0
 
LVL 1

Accepted Solution

by:
BETTY earned 40 total points
ID: 1449808
I had this problem in a program I made: when I refreshed the recordset of the Dbgrid (i.e. after a re-sorting or filtering), all column properties were re-set to default.

This is what I made (this example applies to titles and widths only):

1. Create in Module.bas a global variant variable for titles and other for widths (i.e. name them aColTexts and aColWidths).
2. In Form.Load, fill the variables with Array() function.
3. Make a For..Next statement with Array boundary (use LBound and UBound) like:

    Dim nCicle As Long  'It has to be long for LBound/UBound.
    For nCicle = LBound(aColTexts) To UBound(aColTexts)
        f.grdDataGrid.Columns(nCicle).Width = aColWidths(nCicle)
        f.grdDataGrid.Columns(nCicle).Caption = aColTexts(nCicle)
    Next

4. Repeat this code just after you refresh the dbgrid.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

609 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