View Full Version : Grid Selection Question
thisisauniqueusername
10-22-2008, 01:59 PM
I have not found a solution yet on the forums, but am still looking.
I am trying to reproduce a listbox as a Grid (a lot more features i can use with the grid such as multiple colors/fonts on the same line). With a listbox, I can have multiple selection enabled and get the selected rows with ListBox.GetSelected()
If there are multiple rows, it returns multiple indexes in a table.
I can also set the Selected Inexes using ListBox.SetSelected()
Can the same be done with a Grid? The end result, I need to be able to Get which Rows are selected (currently using ListMode), and being able to select Multiple Rows. These rows may not be one after another either.
jassing
10-22-2008, 02:23 PM
Not "directly" as I see it there is no Grid.GetSelectedCells() call; but there are two functions of use:
To determine if any cells are selected:
Grid.GetSelectedCount()
Then you could loop thru the grid looking for cells that are selected via:
Grid.IsCellSelected()
thisisauniqueusername
10-22-2008, 02:45 PM
Not "directly" as I see it there is no Grid.GetSelectedCells() call; but there are two functions of use:
To determine if any cells are selected:
Grid.GetSelectedCount()
Then you could loop thru the grid looking for cells that are selected via:
Grid.IsCellSelected()
mmk thanks jassing, that worked for getting the selected. Pretty fast on a grid of 100-150 objects. The code i used specifically was:
function FindSelectedGrid(strGrid)
if (Grid.GetSelectedCount(strGrid)>0) then
local x=0;
while (x<(Grid.GetRowCount(strGrid)-1)) do -- minus 1 for the header - Remove if no header
x=x+1;
if (Grid.IsCellSelected(strGrid, x, 0)) then
--Do Your action here
Debug.Print("Row:"..x.." is selected. Value of Column 1 is:"..Grid.GetCellText(strGrid, x, 1).."\r\n");
end
end
end
end
FindSelectedGrid("Grid1");
jassing
10-22-2008, 02:56 PM
I tested with a fairly large grid of random data and randomly selected cells -- I expected it to be slower; but seems the grid access is fast...
Glad you got it going.
thisisauniqueusername
10-22-2008, 03:09 PM
Still looking for a way to do multiple selects via Action Calls.
SetSelectedRange works, if they are all one after another. It doesn't seem to work in there are rows in between that are not to be selected though.
Dermot
10-23-2008, 02:36 AM
You can select one or more rows using Grid.SetSelectedRange()
thisisauniqueusername
10-23-2008, 02:49 AM
You can select one or more rows using Grid.SetSelectedRange()
What if I want to select Rows 1,2 and 4, but not Row 3?
thisisauniqueusername
10-23-2008, 04:40 PM
Found a way to do it :)
I just rewrote all of the ListBox functions as Grid Functions.
A sample project demonstrating them all is here:
New functions are:
Grid.ClickWorkAround(strGrid)
Grid.AddItem(strGrid,strText,strData)
Grid.AddItemTable(strGrid,tblData)
Grid.FindItem(strGrid,nStart,strType,strData)
Grid.FindItemAnywhere(strGrid,nStart,intCol,strDat a)
Grid.SetItemData(strGrid,nIndex,strData)
Grid.InsertItem(strGrid,nIndex,strText,strData)
Grid.InsertItemTable(strGrid,nIndex,tblData)
Grid.IsItemSelected(strGrid,nIndex)
Grid.SetItemText(strGrid,nIndex,strText)
Grid.SetItemTable(strGrid,nIndex,tblData)
Grid.GetItemData(strGrid,nIndex)
Grid.GetItemText(strGrid,nIndex)
Grid.GetItemTable(strGrid,nIndex)
Grid.SelectItem(strGrid,nRow)
Grid.DeselectItem(strGrid,nRow)
Grid.GetSelected(strGrid)
Grid.GetSelectedCountCustom(strGrid)
example follows
jassing
10-23-2008, 06:16 PM
Interesting Idea -- I got a # of errors ("not a table" etc from lack of information on how to use it...) and finally got the attached...
Repeated it twice.
Might be a bug for IR
Dermot
10-23-2008, 06:52 PM
I get lots of errors also and the Grid.SelectItem does not seem to work. The c stack error is because you are causing an infinite loop which repeatedly calls the ClickWorkAround() function. You don't need any new function to handle single clicks because the row is selected when you click on it. Worm posted an excellent solution to handle double clicks.
thisisauniqueusername
10-23-2008, 09:16 PM
I get lots of errors also and the Grid.SelectItem does not seem to work. The c stack error is because you are causing an infinite loop which repeatedly calls the ClickWorkAround() function. You don't need any new function to handle single clicks because the row is selected when you click on it. Worm posted an excellent solution to handle double clicks.
Hmm Can't pull up the attached picture (must login and refresh page, but have already logged in and refreshed...) but I am not getting the errors on my end.
I'm not on the 7.5 yet, still on 7.1, perhaps that is why. As far as the Selection goes, I have used part of Worm's example for the double click in the "ClickWorkAround". My specific needs require that multiple non continuous rows, therefore the normal Select won't work. I wrote the Grid.SelectItem as an alternative for the Grid.SelectRange. The workaround isn't for catching single clicks in so much as catching doubleclicks without using a hot spot, and for "selecting" the entire row with a single click while preserving previous selected Rows, and having the ability to select individual rows via actions.
Thank-you for the input though, I will try to reproduce the errors and correct them
thisisauniqueusername
10-23-2008, 09:44 PM
Hmm Can't pull up the attached picture (must login and refresh page, but have already logged in and refreshed...) but I am not getting the errors on my end.
I'm not on the 7.5 yet, still on 7.1, perhaps that is why.
Fix: Fixed a bug where the "Grid.SetSelectedRange" action was not firing the grid's "On Selection Changed" event.
And that's probably why I did not get the error... Well scratch that part of it then
Have you tried with the Grid set to ListMode?
http://www.indigorose.com/webhelp/ams/Program_Reference/Actions/Grid.SetListMode.htm
thisisauniqueusername
10-24-2008, 10:29 AM
the endless loop needs the "Grid.SetSelectedRange" part commented out i believe to quit the endless loop.
Even on Listmode, when inside a function, using the builtin Grid Functions IR provided, I could not see a way to select specifically Lines 1,2,4 and not 3.
The range only appears to select from one start cell to one end cell, and everything in between. Calling multiple SetSelectedRange would end up with only the last one called being selected.
example:
given grid with 4 rows, 4 columns
function myfunct()
Grid.SetSelectedRange("Grid1", 0, 0, 0, 3, true, true); - First row selected only
Grid.SetSelectedRange("Grid1", 1, 0, 1, 3, true, true); - First row deselected, 2nd row selected
Grid.SetSelectedRange("Grid1", 3, 0, 3, 3, true, true); - 2nd row deselected, 4th row selected
end
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.