Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » tracking GridCtrl selection
tracking GridCtrl selection [message #32709] Thu, 02 June 2011 19:01 Go to next message
bushman is currently offline  bushman
Messages: 134
Registered: February 2009
Experienced Member
Please bear in mind that I'm totally newbie in using
GridCtrl, when considering the folowing questions:

Is there a way to track selections in a GridCtrl?
I mean, some method like
Point GetSelectionBegin()

or
Point Get SelectionEnd()


, which returns the (col, row) coordinates for the
selection begin and selection end, respectively.
Unless I'm mistaken, I didn't see any GridCtrl method
that does it, while browsing GridCtrl with Assist.
Apparently, the only public methods related to selection
tracking are GetSelectedCount(), GetSelectedItemsCount()
and GetSelectionData(), which I assume return the number of
rows selected, the number of cells selected and the
selected data, respectively, allthough I do not have
the slightest idea on how to use the third one to retrieve
selected data.
BTW, method GetSelectedItemsCount() returns different
results to the selection count, depending whether you do either
a CTRL+LMB or a Shift+LMB selection (they differ by 1).
In other words, how can I walk through a selection path in GridCtrl,
checking each selected cell content, cell state, etc.,
one by one, once
a user finishes making a selection with the mouse?

Help appreciated, thanks in advance

Re: tracking GridCtrl selection [message #32765 is a reply to message #32709] Tue, 07 June 2011 08:21 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

You can iterate over all cells:
for(int i = 0; i < grid.GetCount(); i++)
  for(int j = 0; j < grid.GetColumnCount(); j++)
  {
      if(grid.IsSelected(i, j))
      {
          ... do anything ...
      }
   }

for checking rows only or you can use this macro
FOREACH_SELECTED_ROW(grid)
{
   PromptOK(Format("Selected row: %d", grid.GetCurrentRow()));
   ... do my code...
}


As you noticed you can also retrieve number of selected rows/cells:
int selectedRows = grid.GetSelectedCount();
int selectedCells = grid.GetSelectedItemsCount();

Quote:


CTRL+LMB or a Shift+LMB selection (they differ by 1)


Thanks. I'll try to fix that.

There are no GetSelectionBegin/End() methods (what should they return if there are multiple selections?)
Re: tracking GridCtrl selection [message #32964 is a reply to message #32765] Sun, 26 June 2011 12:46 Go to previous message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Quote:

CTRL+LMB or a Shift+LMB selection (they differ by 1)

Selected items counter was indeed too small (3 insted of 4 for example) if user clicked on cell and then clicked on another cell holding control key. Now this is fixed. I'm not sure if that fixes your case so please check and if something is still wrong please write how to reproduce it step by step.
Previous Topic: No preprocessor output
Next Topic: How to set GridCtrl header font size?
Goto Forum:
  


Current Time: Thu Apr 18 15:46:51 CEST 2024

Total time taken to generate the page: 0.01633 seconds