March 17th, 2003, 08:13 PM
remove all dbgrid columns
I am trying to clear all the columns on the grid.
ive tried the following
but i get invalid column index on the last column it tries to remove
While dbGrid.Columns.Count <> 0
March 17th, 2003, 11:28 PM
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?
March 18th, 2003, 02:08 AM
still same thing, i added a datagrid to a form an did
an i get the error still. It doesnt remove the last column if i do
Private Sub Form_Load()
While DataGrid1.Columns.Count <> 0
DataGrid1.Columns.Remove 0 when there is only one column it will error
March 18th, 2003, 02:20 AM
hm well nevermind i just did it like this
dbGrid.Visible = False
While dbGrid.Columns.Count > 1
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
dbGrid.Columns.Remove dbGrid.Columns.Count - 1
dbGrid.Visible = True
March 18th, 2003, 09:03 AM
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)
March 18th, 2003, 02:51 PM
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
March 18th, 2003, 03:08 PM
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
March 18th, 2003, 03:22 PM
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.
The datagrid is an ado data grid.
'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
Private Sub fillGrid(ByVal sql As String)
On Error GoTo errInvalidStatement
Set DataGrid1.DataSource = OpenRSro(sql)
MsgBox "An error occured while attempting to execute the query:" & vbCrLf _
& sql & vbCrLf & "Error #: " & Err.Number & vbCrLf & "Error Desc: " & _
On Error GoTo 0
This is designed to use an ado connection and just call the fillGrid function with a correct sql statement.
March 18th, 2003, 05:02 PM
any ideas why i get this error
An error occured while attempting to execute the query:
select * from members
Error #: 7004
Error Desc: The rowset is not bookmarkable.
March 18th, 2003, 05:24 PM
try adding the database name before it.
select * from some_db.members
March 18th, 2003, 06:03 PM
switched grids an works fine now :-)
Last edited by Tewl; March 19th, 2003 at 07:33 AM.