Usage of LoadSQL and Filippo's ListView

normunds

Member
Licensed User
Hi!

I have very limited background in programming (used Lotus Formula and LotusScript in past). Now I'm learning to use basic4ppc. So I'm a newbie here.

I attached a piece of code, which illustrates my problem: if I start frmArtistList, first time it loads Ok, and lets me select any row in listview. But, after closing the frmArtistList and calling it again from frmMain, my listview still holds data, but I can select rows in listview only programmaticaly (through line 13 in sample code). Any attempts manually select any row marks the corresponding line on the screen, but really calls line selected programmatically.

Basic4ppc: v6.90 (with all sql files from v6.8).
Device: HTC X7500 with WM 6.0 (factory ROM).
Desktop: Windows 7 32-bit.

Of course, before posting I searched in b4p documentation and forums. Unfortunately I didn't found a solution for my problem. Looks like I'm overlooking something obvious.

Any help will be highly appreciated.
 

Attachments

  • errorTrap.zip
    598 bytes · Views: 184

mjcoon

Well-Known Member
Licensed User
... but I can select rows in listview only programmaticaly (through line 13 in sample code). Any attempts manually select any row marks the corresponding line on the screen, but really calls line selected programmatically.

Not absolutely sure what you mean by "can select rows in listview only ...".

But there is a problem with many of these "changed" events in B4PPC that they are triggered by both GUI action by user and by program action.

The only way round this (as has been discussed in other threads but won't be easy to find!) is to add a boolean flag, called say "ignoreEvent" which you test in the event Sub. This flag is set in your code before anything which may change the selected row such as frmArtistList.Show or lv.SelectRow(1).

This flag is set to false only after such actions have taken place, so that user action is not ignored.

B4X:
Sub Globals
 Dim ignoreEvent As Boolean
End Sub
'=============================
Sub App_Start
 ignoreEvent = True
 frmMain.Show
 ignoreEvent = False
End Sub
'=============================
Sub cmdArtistList_Click
 lv.New1("frmArtistList", 5, 5, 470, 390)
 lv.LoadSQL(AppPath & "\db.db", "t_artists", "", "id", True)

 ignoreEvent = True
 frmArtistList.Show
 lv.SelectRow(1)
 ignoreEvent = False
End Sub
'=============================
Sub lv_SelectionChanged
 If ignoreEvent Then Return
 Msgbox("Selected Row: " & lv.SelectedRow)
End Sub

Sorry it's a bit clumsy...

Mike.
 

normunds

Member
Licensed User
Hi, Mike!

Thank you for a response.

I tried your code, but got the same result that with my: after second call to frmArtistList, whatever row I select in a listview, mesage says: "Selected row: 1". As far as I know, the first row in a listview is always automatically selected.

Normunds.
 
D

Deleted member 103

Guest
Hi normunds,

try it this way:

PHP:
Sub Globals
End Sub
'==================================================
Sub App_Start
 lv.New1("frmArtistList", 5, 5, 470, 390)
 frmMain.Show
End Sub
'==================================================
Sub cmdArtistList_Click
 lv.Clear
 lv.LoadSQL(AppPath & "\db.db", "t_artists", "", "id", True)

 frmArtistList.Show
 lv.SelectRow(1)
End Sub
'==================================================
Sub lv_SelectionChanged
   If lv.SelectedIndicesCount > 0 Then
       Msgbox("Selected Row: " & lv.SelectedIndicesItem(0))
   End If
End Sub
 
Last edited by a moderator:

normunds

Member
Licensed User
Hi Filippo,

tried your code, and it works like a charm. Thank you very mutch for your great library and for the help with this code.

I would like to ask you one more question regarding usage of listview.dll on the desktop:
where and how I have to specify the listview row color to get it to work on the desktop?

For example, this code will show listview without coloring at first run. If close the frmArtistList and open it again, it shows listview's rows with different coloring:

PHP:
Sub Globals
End Sub
'==================================================
Sub App_Start
lv.New1("frmArtistList", 5, 5, 470, 390)
lv.SetRowColor(cBeige, cSilver)
frmMain.Show
End Sub
'==================================================
Sub cmdArtistList_Click
lv.Clear
lv.LoadSQL(AppPath & "\db.db", "t_artists", "", "id", True)
 
frmArtistList.Show
 
lv.SelectRow(1)
End Sub
'==================================================
Sub lv_SelectionChanged
If lv.SelectedIndicesCount > 0 Then
Msgbox("Selected Row: " & lv.SelectedIndicesItem(0))
End If
End Sub
The same code runs Ok on the device - it shows colored rows in listview at first run. What I'm doing wrong?

Thank you in advance for advice.
 
D

Deleted member 103

Guest
the function lv.Clear deletes any settings.
In your case you need to adjust the colors for each lv.LoadSql again.

PHP:
Sub Globals
End Sub
'==================================================
Sub App_Start
lv.New1("frmArtistList", 5, 5, 470, 390)

frmMain.Show
End Sub
'==================================================
Sub cmdArtistList_Click
lv.Clear
lv.LoadSQL(AppPath & "\db.db", "t_artists", "", "id", True)
lv.SetRowColor(cBeige, cSilver)
frmArtistList.Show
 
lv.SelectRow(1)
End Sub
==================================================
Sub lv_SelectionChanged
If lv.SelectedIndicesCount > 0 Then
Msgbox("Selected Row: " & lv.SelectedIndicesItem(0))
End If
End Sub
 

normunds

Member
Licensed User
Thanks for a trial, Filippo.

Unfortunately this time your code doesn't do the job. I mean, execution of lv.SetRowColor gives a visible result only starting from second run of the frmArtistList.

If you kindly agree to try it on your PC - I attached a full code sample with db and forms.

1. Start the app, and click the button "List of artists". I think, you will see the listview with white background.
2. Close the form.
3. Click the button "List of artists". You will see the listview with colored rows.

On PPC the same code gives me a listview with coloured bacground at first run of frmArtistList.
 
D

Deleted member 103

Guest
OK, so it must work ...

PHP:
Sub Globals
End Sub
'==================================================
Sub App_Start
 lv.New1("frmArtistList", 5, 5, 470, 390)
 lv.SetRowColor(cBeige, cSilver)

 frmMain.Show
End Sub
'==================================================
Sub cmdArtistList_Click
 lv.Clear
 lv.LoadSQL(AppPath & "\db.db", "t_artists", "", "id", True)
 lv.View = lv.ViewAsDetails
 lv.SetRowColor(cBeige, cSilver)
 
 frmArtistList.Show
 
 lv.SelectRow(1)
End Sub
'==================================================
Sub lv_SelectionChanged
    If lv.SelectedIndicesCount > 0 Then
         Msgbox("Selected Row: " & lv.SelectedIndicesItem(0))
    End If
End Sub
 
Top