The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages - More
> Visual Basic Programming
|
remove all dbgrid columns
Discuss remove all dbgrid columns in the Visual Basic Programming forum on Dev Shed. remove all dbgrid columns Visual Basic Programming forum discussing VB specific programming information. Quickly prototype and build applications with this robust and simple language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

March 17th, 2003, 07:13 PM
|
 |
Contributing User
|
|
Join Date: Oct 2002
Posts: 51
Time spent in forums: 3 h 12 m 31 sec
Reputation Power: 11
|
|
|
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
|

March 17th, 2003, 10:28 PM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
|
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, 01:08 AM
|
 |
Contributing User
|
|
Join Date: Oct 2002
Posts: 51
Time spent in forums: 3 h 12 m 31 sec
Reputation Power: 11
|
|
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
|

March 18th, 2003, 01:20 AM
|
 |
Contributing User
|
|
Join Date: Oct 2002
Posts: 51
Time spent in forums: 3 h 12 m 31 sec
Reputation Power: 11
|
|
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
|

March 18th, 2003, 08:03 AM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
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, 01:51 PM
|
 |
Contributing User
|
|
Join Date: Oct 2002
Posts: 51
Time spent in forums: 3 h 12 m 31 sec
Reputation Power: 11
|
|
|
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, 02:08 PM
|
 |
Contributing User
|
|
Join Date: Oct 2002
Posts: 51
Time spent in forums: 3 h 12 m 31 sec
Reputation Power: 11
|
|
|
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, 02:22 PM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
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.
|

March 18th, 2003, 04:02 PM
|
 |
Contributing User
|
|
Join Date: Oct 2002
Posts: 51
Time spent in forums: 3 h 12 m 31 sec
Reputation Power: 11
|
|
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.
|

March 18th, 2003, 04:24 PM
|
 |
/(bb|[^b]{2})/
|
|
Join Date: Nov 2001
Location: Somewhere in the great unknown
|
|
|
try adding the database name before it.
i.e.
select * from some_db.members
|

March 18th, 2003, 05:03 PM
|
 |
Contributing User
|
|
Join Date: Oct 2002
Posts: 51
Time spent in forums: 3 h 12 m 31 sec
Reputation Power: 11
|
|
|
Last edited by Tewl : March 19th, 2003 at 06:33 AM.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|