wrong selected item
Hi Klaus ,
I tried to modify my application based on your exemple, but it doesn't metter what cell i click the rc is (col 5 ; row 19).
I attached my app. Could you advice me how can a solve the problem ?
Thk
Sorry the zip file is bigger than the maximum alowed, for this reason i put the code here.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim sql1 As SQL
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Begin - Change for Database>>>>>>>>>>>>>>>>>>>>>>>>>>
Dim DBFileName As String : DBFileName = "countries.db"
Dim DBTableName As String : DBTableName = "datePers"
'<<<<<<<<<<<<<<<<<<<<<<<<<<<<<End - Change for Database>>>>>>>>>>>>>>>>>>>>>>>>>>
' Dim DBFileDir As String : DBFileDir = File.DirInternal
Dim DBFileDir As String : DBFileDir = File.DirDefaultExternal
Dim sqltxt As String
Dim cur As Cursor
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim spnGrupe As Spinner
Dim spnValoare As Spinner
Dim spnOre As Spinner
Dim spnstare As Spinner
Dim spnsport As Spinner
Dim lbltitlu As Label
Dim txtnume As EditText
Dim txtprenume As EditText
Dim txttelefon As EditText
Dim txtmail As EditText
Dim txtdatanastere As EditText
Dim CsCal As CustomCalendar
Dim pnlcamp As Panel
Dim l As Label
''---------------------------------------------------------------------------------
Dim nrrand As Int
Dim nrcol As Int
Dim SV As ScrollView
Dim header As Panel
Dim HeaderColor, TableColor, FontColor, HeaderFontColor As Int
Dim FontSize As Float
HeaderColor = Colors.Gray
HeaderFontColor = Colors.White
Type RowCol (Row As Int, Col As Int)
Dim SelectedRowColor As Int : SelectedRowColor=Colors.LightGray
Dim selectedItems As Map ''+18.11
Dim cellcolor As Int
'Table settings
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
If FirstTime Then
sql1.Initialize(DBFileDir, DBFileName, True)
End If
Activity.LoadLayout("inregistrare")
selectedItems.Initialize ''+18.11
grupe
valoare
ore
sporturi
stare
incarc_tabel
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
#Region"Populez campuri si tabel"
Sub incarc_tabel
Dim colwidth As Int
Dim rowhight As Int
rowhight=30dip
nrcol=6
Dim rand(nrcol) As String
Dim numeHeader() As String
numeHeader=Array As String("id","Nume","Prenume","NumarOre","Telefon","DataNastere")
colwidth = SV.Width /nrcol
'' adaug header
header.Initialize("")
For x = 0 To nrcol - 1
Dim lb As Label
lb.Initialize("header")
lb.Text = numeHeader(x)''numeHeader(i)
lb.Gravity = Gravity.CENTER
lb.TextSize = FontSize
lb.Color = HeaderColor
lb.TextColor = HeaderFontColor
lb.Tag = x
header.AddView(lb, colwidth * x, 0, colwidth, rowhight)
Next
Activity.AddView(header, SV.Left, SV.Top - rowhight, SV.Width, rowhight)
sqltxt="Select id,nume,prenume,nrore,telefon,datanastere from datepers"
cur=sql1.ExecQuery(sqltxt)
For y=0 To cur.RowCount -1
cur.Position =y
rand(0)=cur.GetInt("id")
rand(1)=cur.GetString("nume")
rand(2)=cur.Getstring("prenume")
rand(3)=cur.GetInt("nrOre")
rand(4)=cur.GetString("telefon")
rand(5)=cur.GetString("datanastere")
For i=0 To nrcol -1
l.Initialize("cell")
l.Gravity =Gravity.CENTER
l.TextSize =18
l.Text =rand(i)
l.TextColor =HeaderFontColor
Dim rc As RowCol
rc.Initialize
rc.Col =i
rc.Row =y
l.Tag =rc
SV.Panel.AddView(l,colwidth*i,rowhight*y,colwidth,rowhight)
Next
Next
cur.Close
SV.FullScroll(True)
SV.Panel.Height = rowhight * y
End Sub
Sub cell_click
Dim rc As RowCol
Dim l As Label
l=Sender
rc=l.Tag
If selectedItems.Size <>1 Then
selectedRow(rc.Row ,rc.Col )
End If
''Dim l As Label
'' Dim rc As RowCol
'' l = Sender
'' rc = l.Tag
'' Activity.Title = "Row " & rc.Row & " Col " & rc.Col &" / " & l.Text
End Sub
Sub selectedRow(row As Int , selcol As Int ) ''18.11
Dim col , index As Int
Msgbox(col&";"&row,"")
End Sub
Sub grupe
spnGrupe.Clear
sqltxt="select * from grupe"
cur=sql1.ExecQuery(sqltxt)
If cur.RowCount > 0 Then
spnGrupe.Add("Selecteaza Grupa")
For i=0 To cur.RowCount -1
cur.Position =i
spnGrupe.Add(cur.GetString("grupe"))
Next
End If
cur.Close
End Sub
Sub sporturi
spnsport.Clear
sqltxt = "select * from activitati"
cur=sql1.ExecQuery(sqltxt)
If cur.RowCount > 0 Then
spnsport.Add("Selecteaza Activitatea Sportiva")
For i=0 To cur.RowCount -1
cur.Position =i
spnsport.Add(cur.GetString("sport"))
Next
End If
cur.Close
End Sub
Sub valoare
spnValoare.Clear
sqltxt = "select * from valori"
cur=sql1.ExecQuery(sqltxt)
If cur.RowCount>0 Then
spnValoare.Add("Selecteaza Valoare")
For i=0 To cur.RowCount -1
cur.Position =i
spnValoare.Add(cur.GetString("valori"))
Next
spnValoare.SelectedIndex=0
End If
cur.Close
End Sub
Sub ore
spnOre.Clear
sqltxt = "select ore from nrore"
cur=sql1.ExecQuery(sqltxt)
If cur.RowCount > 0 Then
spnOre.Add("Selecteaza Numarul de ore")
For i=0 To cur.RowCount -1
cur.Position =i
spnOre.Add(cur.GetString("ore"))
Next
spnOre.SelectedIndex =0
End If
cur.Close
End Sub
Sub stare
spnstare.AddAll(Array As String("Activ","Inactiv"))
End Sub
#End Region
#Region"Functii adaugare"
Sub addDate (comanda As String)
''FPDataNastere=DateTime.DateParse(FPDataNastere)
sql1.BeginTransaction
''sql1.ExecNonQuery("Insert INTO datePers (nume,prenume,telefon,adrMail,datanastere) VALUES ('" & FPnume & "','" & FPprenume & "','" & FPtelefon & "','" & FPadrmail & "','" & FPdata & "')")
sql1.ExecNonQuery(comanda)
sql1.TransactionSuccessful
sql1.EndTransaction
End Sub
#End Region
Sub btnSalveaza_Click
Dim data As String
Dim now As Long
Dim SQL As String
Dim idClient As Int
If txtnume.Text = "Nume" Then
Msgbox("Nu ai completat campul Nume","Eroare Operare")
Return
End If
If txtprenume.Text ="Prenume" Then
Msgbox("Nu ai completat campul Prenume","Eroare Operare")
Return
End If
If txttelefon.Text ="Telefon" Then
Msgbox("Nu ai completat campul Telefon","Eroare Operare")
Return
End If
If spnGrupe.selectedItem="Selecteaza Grupa" Then
Msgbox("Nu ai selectat Grupa","Eroare Operare")
Return
End If
If spnValoare.selectedItem = "Selecteaza Valoare" AND spnOre.selectedItem<>"Selecteaza Numarul de ore" Then
Msgbox("Ai uitat sa selectezi Valoare","Eroare Operare")
Return
End If
If spnOre.selectedItem ="Selecteaza Numarul de ore" AND spnValoare.selectedItem <> "Selecteaza Valoare" Then
Msgbox("Ai uitat sa selectezi valoarea","Eroare Operare")
Return
End If
'' Inserez datele personalre
SQL="Insert INTO datePers (nume,prenume,telefon,adrMail,datanastere,grupa,sport,stare)VALUES ('" & txtnume.Text & "','" & txtprenume.Text & "','" & txttelefon.Text & "','" & txtmail.Text & "','" & txtdatanastere.Text & "','" & spnGrupe.selectedItem & "','" &spnsport.selectedItem &"','" & spnstare.selectedItem &"')"
addDate(SQL)
'' Caut ID de client
SQL="Select id from datePers where nume = '" &txtnume.Text &"'and prenume='"& txtprenume.Text &"'and telefon='" &txttelefon.Text &"'and adrMail='"&txtmail.Text &"'"
cur=sql1.ExecQuery(SQL)
For i=0 To cur.RowCount -1
cur.Position =i
idClient=cur.GetInt("id")
Next
cur.Close
''daca se face plata la inregistrare inserez in activZilnica
DateTime.DateFormat="yyyy-MM-dd"
If spnValoare.selectedItem <> "Selecteaza Valoare" Then
data=DateTime.Date(now)
SQL="Insert INTO activZilnica(idpers,data,suma)VALUES('"& idClient &"','" & data &"','" &spnValoare.selectedItem &"')"
addDate(SQL)
End If
incarc_tabel
End Sub
Sub txtTelefon_FocusChanged (HasFocus As Boolean)
If HasFocus=True AND txttelefon.Text = "Telefon" Then
txttelefon.Text =""
Else
If txttelefon.Text ="" Then
txttelefon.Text ="Telefon"
End If
End If
End Sub
Sub txtPrenume_FocusChanged (HasFocus As Boolean)
If HasFocus=True AND txtprenume.Text = "Prenume" Then
txtprenume.Text =""
Else
If txtprenume.Text ="" Then
txtprenume.Text ="Prenume"
End If
End If
End Sub
Sub txtNume_FocusChanged (HasFocus As Boolean)
If HasFocus=True AND txtnume.Text = "Nume" Then
txtnume.Text =""
Else
If txtnume.Text ="" Then
txtnume.Text ="Nume"
End If
End If
End Sub
Sub txtMail_FocusChanged (HasFocus As Boolean)
If HasFocus=True AND txtmail.Text = "Adresa Mail" Then
txtmail.Text =""
Else
If txtmail.Text ="" Then
txtmail.Text ="Adresa Mail"
End If
End If
End Sub
Sub txtDataNastere_FocusChanged (HasFocus As Boolean)
If HasFocus = True Then
CsCal.Initialize(Me,"CsCal",100%x,100%y,DateTime.Now)
Activity.AddView(CsCal.AsView,0,0,100%x,100%y)
CsCal.ShowCalendar(True)
End If
End Sub