Link to home
Start Free TrialLog in
Avatar of SIMONBRATT
SIMONBRATT

asked on

DBGrid, Column reset when Refresh

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
Avatar of trkcorp
trkcorp

Is it a bound grid? If so, refreshing the data control rather than the grid itself should leave set attributes intact.
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

Avatar of SIMONBRATT

ASKER

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?
too complicated for a beginner, when does the grid get visibly updated?
ASKER CERTIFIED SOLUTION
Avatar of BETTY
BETTY
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial