[Gambas-user] Gridview Select Multiple rows.
Michael
mdavies5 at ...169...
Fri Nov 5 12:59:52 CET 2010
Thanks,
I will give this a try.
Michael
On 05/11/10 18:09, user wrote:
> Example with ListView control lswResults
>
> -----------------------------------------------
> ' Gambas class file
> PRIVATE sFileArray AS String[] = [""]
> PRIVATE iKeyArray AS Integer[] = [0]
> PRIVATE bKeyControlPressed AS Boolean = FALSE
> PRIVATE bSellectAllPressed AS Boolean = FALSE
>
>
>
> PUBLIC SUB Form_Open()
> sFileArray.Clear 'reset private array
> iKeyArray.Clear 'reset private array
> END
>
>
>
> PUBLIC SUB btnSelectAll_Click()
> bSellectAllPressed = TRUE
> lswResults.SelectAll
> END
>
>
> PUBLIC SUB lswResults_KeyRelease()
>
> IF Key.Control = TRUE THEN
> bKeyControlPressed = FALSE
> ENDIF
>
>
> END
>
> PUBLIC SUB lswResults_KeyPress()
>
> IF Key.Control = TRUE THEN
> bKeyControlPressed = TRUE
> ENDIF
>
> END
>
>
>
> PUBLIC SUB lswResults_Select()
>
> DIM iKey AS Integer = 0
> DIM sElement AS String = ""
> DIM sFile AS String[] = [""]
> DIM sRow AS String = ""
> DIM iCounter AS Integer
>
> sFile.Clear
> sRow = Replace$(lswResults.Current.Text, " ", "\n") 'format string
> sFile = Split(sRow, "\n") 'split row and take only path, reject virus
> description
>
> ' PRINT lswResults.Current.Text
> ' PRINT sFile[0]
>
>
> 'HERE IS WHAT YOU LOOK FOR -------------------------------
> 'if user select with CTRL
> IF bKeyControlPressed = TRUE THEN
> 'check if in sFileArray there is a current selection
> IF sFileArray.Count> 0 THEN
> 'if there is one user clicked unselect
> IF sFileArray.Exist(sFile[0]) THEN
> 'delete entry of current selected item from sFileArray and from
> iKeyArray
> iKey = sFileArray.Find(sFile[0]) 'find key
> sFileArray.Delete(iKey) 'delete selection according found key
> iKey = iKeyArray.Find(lswResults.Current.Key) 'find key for second
> array
> iKeyArray.Delete(iKey) 'delete selection according found key
> ' lswResults.Current.Selected = FALSE
> ELSE
> 'if there is not, add the new selection
> sFileArray.Add(sFile[0])
> iKeyArray.Add(lswResults.Current.Key)
> ENDIF
> ELSE 'add into Arrays for first time, sFileArray.Count=0
> sFileArray.Add(sFile[0])
> iKeyArray.Add(lswResults.Current.Key)
> ENDIF
> ELSE IF bSellectAllPressed = TRUE THEN 'if user pressed btnSelectAll
> sFile.Clear 'clear array
> sFileArray.Clear
> iKeyArray.Clear
>
> lswResults.MoveFirst 'add all items of listview into arrays
> FOR iCounter = 0 TO lswResults.Count - 1
> sRow = Replace$(lswResults[lswResults.Item.Key].Text, " ", "\n")
> 'format string
> sFile = Split(sRow, "\n") 'split row and take only path, reject virus
> description
> sFileArray.Add(sFile[0])
> iKeyArray.Add(lswResults[lswResults.Item.Key].Key)
> lswResults.MoveNext
> NEXT
> bSellectAllPressed = FALSE
>
> ELSE 'user makes single clicks
> sFileArray.Clear
> iKeyArray.Clear
>
> sFileArray.Add(sFile[0])
> iKeyArray.Add(lswResults.Current.Key)
>
> ENDIF
> '--------------------------------------------------------
>
>
> ' PRINT "----------------------"
> ' FOR EACH sElement IN sFileArray
> ' PRINT sElement
> ' NEXT
>
> END
>
>
> On Fri, 2010-11-05 at 15:09 +1100, Michael wrote:
>> I'm a newbie to Gambas and very impressed. Managed to solve all my
>> queries and port apps from VB. However I have one problem that has me beat:)
>> I have a GridView with Mode = Multiple and can select multiple rows;
>> either sequentially or at random. So far so good as similar to VB.
>> I want to loop through the selected items and take some action on each
>> item. eg: Delete the row.
>> I cannot find a way to read the selected row. The Gridview.Row property
>> only returns the last selected row.
>> Typically my grid may contain 1000 rows and I use this function to
>> delete old records. It would be tedious one at a time. I could get
>> around it by asking the user to enter a cutoff date or range of row
>> numbers to delete but this raises the question "What is the point of
>> having a Multiple mode attribute?"
>> Thanks
>> Mike
>>
>> ------------------------------------------------------------------------------
>> The Next 800 Companies to Lead America's Growth: New Video Whitepaper
>> David G. Thomson, author of the best-selling book "Blueprint to a
>> Billion" shares his insights and actions to help propel your
>> business during the next growth cycle. Listen Now!
>> http://p.sf.net/sfu/SAP-dev2dev
>> _______________________________________________
>> Gambas-user mailing list
>> Gambas-user at lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
> ------------------------------------------------------------------------------
> The Next 800 Companies to Lead America's Growth: New Video Whitepaper
> David G. Thomson, author of the best-selling book "Blueprint to a
> Billion" shares his insights and actions to help propel your
> business during the next growth cycle. Listen Now!
> http://p.sf.net/sfu/SAP-dev2dev
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
>
>
More information about the User
mailing list