I'm having a very weird problem with the MSHFlexGrid, unless I'm missing something fundamental here... I put together a minimum of code to reproduce the behavior;
Create and save a new project, drop in an MSHFlexGrid and three command buttons, add a refernce to Microsoft ADO Library, and use the following code:
For a datasource, save the following to MyData.csv in the application folder:
The behavior:
1. When you run the program, all the records are shown in the grid, and you can click on any cell in the grid.
2. Click "Command1", and only records with category=1 are shown, as expected... and you can still click anywhere you want in the grid.
3. Click "Command2", and only records with category=2 are shown, and everything works as expected.
4. Click "Command3"... now no records are returned, and you see a blank grid (except for the header row). Still, behaving as expected.
5. Click "Command1", and again, and only records with category=1 are shown.
BUT... now you can't click and select cells in the grid! Or at least, I can't! Using the keyboard to navigate the grid at this point is even stranger. Is this a bug, or am I doing something I shouldn't?
Create and save a new project, drop in an MSHFlexGrid and three command buttons, add a refernce to Microsoft ADO Library, and use the following code:
Code:
Option Explicit
Dim Conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cm As ADODB.Command
Private Sub Form_Load()
Set Conn = New ADODB.Connection
Conn.Open _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & ";" & _
"Extended Properties=""text;HDR=Yes;FMT=Delimited"""
Set cm = New ADODB.Command
cm.ActiveConnection = Conn
cm.CommandType = adCmdText
cm.CommandText = "SELECT * FROM MyData.csv"
Set rs = New ADODB.Recordset
rs.Open cm, , adOpenKeyset, adLockOptimistic
Set MSHFlexGrid1.DataSource = rs
End Sub
Private Sub Command1_Click()
ShowCategory 1
End Sub
Private Sub Command2_Click()
ShowCategory 2
End Sub
Private Sub Command3_Click()
ShowCategory 3
End Sub
Private Sub ShowCategory(iCategoryID As Integer)
cm.CommandText = "SELECT * FROM MyData.csv WHERE category = " & iCategoryID
rs.Close
rs.Open cm, , adOpenKeyset, adLockOptimistic
Set MSHFlexGrid1.DataSource = rs
End Sub
For a datasource, save the following to MyData.csv in the application folder:
Code:
category,name
1,mike
1,joe
1,harry
1,tom
2,al
2,bob
2,chris
The behavior:
1. When you run the program, all the records are shown in the grid, and you can click on any cell in the grid.
2. Click "Command1", and only records with category=1 are shown, as expected... and you can still click anywhere you want in the grid.
3. Click "Command2", and only records with category=2 are shown, and everything works as expected.
4. Click "Command3"... now no records are returned, and you see a blank grid (except for the header row). Still, behaving as expected.
5. Click "Command1", and again, and only records with category=1 are shown.
BUT... now you can't click and select cells in the grid! Or at least, I can't! Using the keyboard to navigate the grid at this point is even stranger. Is this a bug, or am I doing something I shouldn't?