#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    51
    Rep Power
    12

    remove all dbgrid columns


    I am trying to clear all the columns on the grid.

    ive tried the following

    Code:
      While dbGrid.Columns.Count <> 0
        dbGrid.Columns.Remove 0
      Wend
    but i get invalid column index on the last column it tries to remove
    Tewl
  2. #2
  3. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    I do not get the same error.
    Have you placed a breakpoint and stepped through to see what is going on and does it remove the last column?
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    51
    Rep Power
    12
    still same thing, i added a datagrid to a form an did
    Code:
    Private Sub Form_Load()
      While DataGrid1.Columns.Count <> 0
        DataGrid1.Columns.Remove 0
      Wend
    End Sub
    an i get the error still. It doesnt remove the last column if i do

    DataGrid1.Columns.Remove 0 when there is only one column it will error
    Tewl
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    51
    Rep Power
    12
    hm well nevermind i just did it like this

    Code:
      dbGrid.Visible = False
      While dbGrid.Columns.Count > 1
        dbGrid.Columns.Remove 0
      Wend
      Dim TblFields As Integer
      TblFields = MyRset.Fields.Count
      If TblFields > 0 Then
        TblFields = TblFields - 1
        For t = 0 To TblFields
          dbGrid.Columns.Add(t).Caption = MyRset.Fields(t).Name
        Next t
      End If
      dbGrid.Columns.Remove dbGrid.Columns.Count - 1
      dbGrid.Visible = True
    Tewl
  8. #5
  9. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    just out of curiosity...
    what service pack are you running?
    have you tried it with another grid control? (ie truedbgrid6|7)
    .
    .
    and of course I have to ask...are you a bama or auburn fan? (fellow bama native)
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    51
    Rep Power
    12
    Micorosoft DataGrid Control 6.0 (SP5) (OLEDB)

    no I haven't really tried any other. I was using flexgrid but I dont like the look of it.

    hm Bama prolly just cause my parents are auburn fans tho I never could agree with them
    Tewl
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    51
    Rep Power
    12
    I'm working on a program to help me view an edit my mysql databases. I'm don't know much about database programs I'm just trying to pick up as much as I can as I go. I found some examples but they all use the .mdb files as datasource an I was wondering is there another way I can list the data in the datagrid.
    I know Recordset.getString as the data an each row is divided by a vbcr but thats about it
    Tewl
  14. #8
  15. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    are you manually going through the resultset and entering the data into the grid or are you just binding the grid to the resultset?

    Let me show you one of my little database viewers that I made a while back. It doesn't deal with mysql, it is meant to deal with a db2 database, but the concept should be the same once you have connected to the database.

    Code:
    'opens an ado read only recordset
    Public Function OpenRSro(sql As String) As ADODB.Recordset
        Dim rst As ADODB.Recordset
        Set rst = New ADODB.Recordset
        rst.Open sql, cn, adOpenForwardOnly
        Set OpenRSro = rst
    End Function
    
    Private Sub fillGrid(ByVal sql As String)
        On Error GoTo errInvalidStatement
        Set DataGrid1.DataSource = OpenRSro(sql)
        Exit Sub
    errInvalidStatement:
        MsgBox "An error occured while attempting to execute the query:" & vbCrLf _
            & sql & vbCrLf & "Error #: " & Err.Number & vbCrLf & "Error Desc: " & _
            Err.Description
        On Error GoTo 0
    End Sub
    The datagrid is an ado data grid.
    This is designed to use an ado connection and just call the fillGrid function with a correct sql statement.
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    51
    Rep Power
    12
    any ideas why i get this error

    Code:
      An error occured while attempting to execute the query:
      select * from members
      Error #: 7004
      Error Desc: The rowset is not bookmarkable.
    Tewl
  18. #10
  19. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    try adding the database name before it.
    i.e.
    select * from some_db.members
  20. #11
  21. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2002
    Posts
    51
    Rep Power
    12
    switched grids an works fine now :-)

    MySQL Client
    Last edited by Tewl; March 19th, 2003 at 06:33 AM.
    Tewl

IMN logo majestic logo threadwatch logo seochat tools logo