Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » Get the row numbers currently drawn
|
|
|
|
Re: Get the row numbers currently drawn [message #39911 is a reply to message #39895] |
Fri, 10 May 2013 23:04   |
Sender Ghost
Messages: 301 Registered: November 2008
|
Senior Member |
|
|
Hello, Crydev.
crydev wrote on Thu, 09 May 2013 17:13 |
I was wondering. Is there a possibility to get the row numbers of the rows currently drawn? By that, I mean the rows that are visible to the user in the ArrayCtrl.
|
After looking at ArrayCtrl::RefreshSel() method, I created following example to get visible range of rows:
Toggle Spoiler
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
Tuple2<int, int> GetVisibleRange(const ArrayCtrl& array)
{
int from, to;
const int last = array.GetCount() - 1;
if (last >= 0) {
const int cy = array.GetSize().cy - 1,
sb = array.GetScroll();
from = array.GetLineAt(sb),
to = array.GetLineY(last) <= cy ? last : array.GetLineAt(sb + cy);
}
if (last < 0 || IsNull(to) || from > to)
from = to = -1;
return MakeTuple(from, to);
}
class App : public TopWindow {
public:
typedef App CLASSNAME;
App();
ArrayCtrl list;
DropList dropCount;
void OnGet();
void OnSelect();
};
App::App()
{
Title(t_("The visible range of rows for ArrayCtrl"));
Sizeable().Zoomable();
SetRect(Size(640, 480));
list.AddRowNumColumn("Index").SetDisplay(StdCenterDisplay()).HeaderTab().SetAlign(ALIGN_CENTER);
const int count = 0x100000;
list.SetVirtualCount(count);
dropCount.AddButton().SetLabel(t_("Get")).Tip(t_("Get the visible range of rows")).Left().WhenPush = THISBACK(OnGet);
dropCount.SetDisplay(StdCenterDisplay()).WhenAction = THISBACK(OnSelect);
dropCount.Add(0, t_("Empty"))
.Add(10, 10)
.Add(count, count)
.SetIndex(2);
Add(list.HSizePosZ(4, 4).VSizePosZ(4, 28));
Add(dropCount.HCenterPosZ(100).BottomPosZ(4, 20));
}
void App::OnSelect()
{
const int index = dropCount.GetIndex();
if (index < 0)
return;
list.SetVirtualCount(dropCount.GetKey(index));
}
void App::OnGet()
{
Tuple2<int, int> range = GetVisibleRange(list);
PromptOK(range.b < 0 ?
t_("The rows are not visible") :
NFormat(t_("From %d to %d"), range.a, range.b));
/* // How to use the result:
RDUMP(range);
if (range.b >= 0)
for (int i = range.a; i <= range.b; ++i)
RLOG(i << ": " << list.Get(i, 0));
*/
}
GUI_APP_MAIN
{
Ctrl::GlobalBackPaint();
App app;
app.Run();
}

Edit: Added comment about how to use the GetVisibleRange function result.
[Updated on: Sun, 12 May 2013 09:25] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Tue Apr 29 09:25:48 CEST 2025
Total time taken to generate the page: 0.03857 seconds
|