MFC DataGrid

Class library usage, coding and language questions.
rotciv
Posts: 26
Joined: Mon May 12, 2014 4:25 pm

MFC DataGrid

Post by rotciv » Mon May 26, 2014 8:53 am

Hello,
I wonder if there are any good examples of how to work with MFC Datagrid (I read a few topics here but havent found needed information)
in particular:
I can get the table and needed cell which I want double click

Code: Select all

Ranorex.Table table=@" ...";
...
Cell cellToLoad= table.Rows[rowNum].Cells[0];
cellToLoad.DoubleClick();
The problem for me is that I dont see how to check if the row with index

Code: Select all

rowNum
is visible.
I.e. sometimes the table is large enough so it doesn't fit to the screen.
so two questions:
1) is there any quick way to know that my row is not visible except searching for the ScrollBar which takes a bit of time? (maybe there are some methods to check the if row with specific index is visible?)
2) when I know that my row is out of visible part - what is the best way to get it visible? Scrolling down is the best way?
3) What method should I use if I want to scroll down knowing the percentage of the scroll length? ie lets assume that when with current settings my scroll bar is on 25% (meaning that visible part is 1/4 of the whole table) and my row is in the middle - so I want to move scrollbar control to the middle of the scroll line. How should I do it?

Thank you for your help
Victor

rotciv
Posts: 26
Joined: Mon May 12, 2014 4:25 pm

Re: MFC DataGrid

Post by rotciv » Mon May 26, 2014 10:55 am

a small update
I am able t set the value of the Scrollbar using

Code: Select all

sb.Value = someParticularValue;
it seems that the scrollbar appears at that location but the datagrid itself is not updated - it is still showing only very top part of the table.
Moreover I I hover the mouse on the scrolbar it jumps back to the initial value.
So I cant move the scrollbar this way

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: MFC DataGrid

Post by krstcs » Tue May 27, 2014 2:02 pm

First, the SetValue method only sets the value of the object in question (here the scrollbar), it does not cause any events to fire. In the case of the scrollbar, it will set the scrollbar's position on the "track" but will not cause the page to scroll. You would be better off using the mouse to click the down arrow on the track.

Second, the row you are looking for should have a Visible property that you can check to determine if it is visible in the viewing window. Visible returns a boolean (true/false).

For example:

Code: Select all

if (<Your Row Object>.Visible)  { ... }
Shortcuts usually aren't...

rotciv
Posts: 26
Joined: Mon May 12, 2014 4:25 pm

Re: MFC DataGrid

Post by rotciv » Thu May 29, 2014 12:09 pm

thank you
Visible is working fine

regarding pressing the Down button - it is not a good option. I have tens of thousands lines in the Table and pressing Down button would take ages.
Currently I am using a method which compares the height of the Indicator to the height of the scroll bar and then knowing the row of the item and total number of rows I am pressing DownPage button several times.

I was wondering if there a straight forward method moving indicator to the needed position.
I know that table contains lets say 10 000 lines and I want to make line 5 000 to be visible. Which means that indicator should be on 50%

Any suggestions?

thanks again,
Victor

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: MFC DataGrid

Post by krstcs » Thu May 29, 2014 1:22 pm

Have you tried specifically invoking the EnsureVisible method on the row you need?

Code: Select all

repo.MyApp.MyRow.EnsureVisible();
Shortcuts usually aren't...

rotciv
Posts: 26
Joined: Mon May 12, 2014 4:25 pm

Re: MFC DataGrid

Post by rotciv » Fri May 30, 2014 4:41 pm

this doesnt do anything at all
after I need to make my Row visible I want to double click in it
so after

Code: Select all

cellToLoad.EnsureVisible();
nothing visually changes, ie grid stays as it is showing the top part (my row is in the middle)

then next line

Code: Select all

cellToLoad.DoubleClick();
clicks something completly wrong


thanks,
Victor

krstcs
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: MFC DataGrid

Post by krstcs » Fri May 30, 2014 5:08 pm

Yeah, the second issue (the click in the wrong place) is because the grid is not moving when you do the EnsureVisible. It is espected.

I would guess that Ranorex, for some reason, believes that the item in question is visible.

Have you tried validating whether the element is visible or not?

Code: Select all

Report.Info("USER", "ELEMENT " + (<Your Item>.Element.Visible ? "" : "NOT") + " VISIBLE");
If that returns true AND the object IS actually out side of the view box, then the problem is either Ranorex miscalculating the Visible attribute, or the app misreporting the location/visible status. If it returns false, then I don't know.
Shortcuts usually aren't...

rotciv
Posts: 26
Joined: Mon May 12, 2014 4:25 pm

Re: MFC DataGrid

Post by rotciv » Sat May 31, 2014 9:38 am

I will try on Monday at work
but the real question is not what Ranorex considers but rather does it provide a simple method how to move the slide

I mean the task is simple enough -
1) Ranorex recognizes the SlideBar and Indicator in it.
2) currently indicator is on the very top position and I want to move it to position 50% on the slide
3) there is a method MoveTo which doesnt do much to the associated table - it just shows temporary that indicator is in the middle


it seems as a Ranorex bug to me.
Could it be raised and solved?

otherwise I am using less efficient method of pressing pagedown several times. this button needs to be found as well which takes good few seconds

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: MFC DataGrid

Post by Support Team » Thu Jun 05, 2014 1:50 pm

HI Victor,

I think you misunderstood the MoveTo()method. Let me explain it:
The MoveTo()-method moves the mouse cursor to the specified element. Please have a look at our Online Documentation for more information.

If ensureVisible() is not working you can also try to use
repo.Application.Cell.Select();
if Select() does not work either, you can use this little workaround to move your slider to the desired position
public void Scroll()
		{
			double currpos, minpos, maxpos, size;
			int stepsize = 3; //increase this value to move the indicator faster
			
			size = repo.Application.ScrollVertical.Vertical.PageSize; //gets the size of the indicator
			minpos = repo.Application.ScrollVertical.Vertical.MinValue; //gets the lowest position of the indicator
			maxpos = repo.Application.ScrollVertical.Vertical.MaxValue; //gets the maximum value			
			currpos = repo.Application.ScrollVertical.Vertical.Value; //gets the current value of the indicator
            repo.Application.ScrollVertical.SomeIndicator.MoveTo(); //Moves mouse to the scrollbar indicator
			Mouse.ButtonDown(System.Windows.Forms.MouseButtons.Left); //Holds down the left mouse button
			
			Point po = Mouse.Position; //gets the current position of your mouse
			
			while(currpos<(maxpos-size)+1) //+1 to get to the last row
			{
				currpos = repo.Application.ScrollVertical.Vertical.Value; //gets the current position of the indicator
				Report.Info("current"+currpos.ToString());
				po = Mouse.Position; //gets the current position of your mouse
				Mouse.MoveTo(po.X,po.Y+stepsize); //moves the mouse to a new position
				if(repo.Application.LookFor.Visible)
				{
					Report.Info("Cell was found");
					break; //exits when the cell is visible
				}
			}
			Mouse.ButtonUp(System.Windows.Forms.MouseButtons.Left); //Releases the mouse button
			repo.Application.LookFor.Click(); //Clicks in the cell
		}
Please let us know if this solves your problem.

Regards,

Markus (S)

rotciv
Posts: 26
Joined: Mon May 12, 2014 4:25 pm

Re: MFC DataGrid

Post by rotciv » Wed Jun 18, 2014 9:07 am

thanks Markus
I was out for a while
I will try this and will let you know

Kind regards,
Victor

rotciv
Posts: 26
Joined: Mon May 12, 2014 4:25 pm

Re: MFC DataGrid

Post by rotciv » Thu Jul 10, 2014 8:41 am

thanks Markus for your help!
cell option doesnt work but the workaround is working well

Kind regards,
Victor