We help IT Professionals succeed at work.

Setting the cursor on a datawindow

gvijay1
gvijay1 asked
on
Experts,

I have a small problme that I am trying to fix. This is the scenario. I have several tab pages. When I click on say tab 2, I want the tab page to open up, with the cursor on the first field of the tab page. Also, note that there is a datawindow that exists on this tab page.

Thus, is there any function to move the cursor to a particular field on the datawindow??

Comment
Watch Question

Commented:
Of course,

In your datawindow set the tab order to the column you want to focused and all others greater then 10.
In your tab pages (Tab control), In the selectionchanged EVENT write if the new index(You find the new index parameter in the paste arguments of the selectionchanged event of the tab control) is the iab oage say tabpage 2 then Set focus to dw with the Setfocus().

1)    In the Datawindow set the tab orders to 10 which column you want to focused first. (In datawindow painter Menu Design -> Tab orders.

2)   In the Tab control script in Selectionchanged event write

IF newindex = 2 THEN //It means the tabpage 2 (Second tabpage where your dw is placed)
    tabpage_2.dw_1.SetFocus() //you tabpage name and datawindowwindow name
END IF

When you will set a focus to the dw, then dw set to the focus to your column which have lowest taborder number.

You can use the newindex and oldindex arguments of the selectionchanged event to know in which tabpage you are.

I think these two points can solve it.


Please let me know.

Bhatti

Author

Commented:
Hi,

There is a slight problme with this approach, though. The reason is, tab pages 1 and 2 read share the same datawindow. As a result, depending on the tab page that is selected, different fields on the datawindow are enabled and disabled depending on the selection.

Thus, say there are 10 fields on the datawindow and fields 5-10 are displayed when the second tab page is selected.....I then want the cursor to be on the first field of the 2nd tab page (field 5) when then selection is made. The above approach will no let me do so.

I hope this is clear?!?!

Commented:
When you select the second tabpage use the function setcolumn().

Setcolumn() function will set the cursor to the column you asked.

tab_1.tabpage_2.dw_1.SetColumn(5).

You will see that the cursor appear on the field(column) 5, if column taborder is greater then 0.

Do the same as above only after setting focus to the DW then use the SetColumn(col_number) function.
IF newindex = 2 THEN //It means the tabpage 2 (Second tabpage where your dw is placed)
    tabpage_2.dw_1.SetFocus() //you tabpage name and datawindowwindow name
    tabpage_2.dw_1.SetColumn(5) //If the column number you want to focus is fifth column in your                                                               //datawindow placed in(can be shared).
END IF


exact column number you can find in datawindow painter in Menu Rows -> column spacifications...

Use this function and please let me know.


Bhatti

Commented:
Hi gvijay1,

In your request "SetColumn(column-number)" is the function to move the cursor to a particular field on the datawindow.

Please let me know. Thanks.


Bhatti


Author

Commented:
hi expert,

I tried your suggestion, but it does not move the cursor to that particular field. I am not sure what the issue is???

Do you have any other suggestions??

Commented:
I did a test with setcolumn() function and it worked.

 So you should look carefully:

1) Write a script in the selectionchanged Event of the tab control.

2) Taborder must be greater then 0.

3)  The name of the datawindow in your tabpage_2,  may be dw_1, dw_2, dw_test and etc.

Please can you write me what happend when you you clicked on the second tabpage?

When you write a script give the dw-name:
IF newindex = 2 THEN //It means that second tabpage and in script get the paste argument newindex
    tabpage_name.dw_name.SetFocus()
    tabpage_name.dw_name.SetColumn(column_number)
END IF

When you clicked on the second page of the Tab control, PB check the tabpage number and if it 2 then set the focus to the DW placed in this tabpage(if there are two then please write the name of the DW you need) and then function SetColumn(column_number) function to get cursor in the particular field in this DW.

May there is another reason, but can be solved if you write me what happend when you clicked on the second tabpage of the tab control.

Bhatti




Commented:
Hi,

Did you try with this solution?

Please let me know.

Bhatti

Author

Commented:
Hi,

I did try with this solution...This is what happened.

1.) I did verify that I am able to get the focus of the datawindow in this case
2.) I tried a GetColumn() and this returns 0. This is strange because when I view the datawindow, there is a tab order ser for all the fields. MOreover, the fields are not protected, cause I am able to access the fields when I manually set the cursor within the field of interest.

Do you know what is going on here??

Commented:
Hi,

Don't use the GetColumn(). If you have no current column, GetColumn() will return you 0.
Please after dw_1.SetFocus() function use the function     SetColumn(column_number). This function will make the written column in the SetColumn(column_number) function the current column.
Please use the SetColumn(column_number) function (and then you will get focus to your requested column) and let me know please.



Thanks

Bhatti.


Author

Commented:
Hi there,

I actually tried the SetFocus() followed by the
SetColumn() to try to set the focus on the field of the column.

However, since I am going from a tab that uses the same dw to another tab that uses the same dw, the SetFocus method is not working, I think. My theory is that the focus was never lost, so, the SetColumn does not work. I even tried taking the focus away from the dw and then setting the focus back to it, but even this does not work.

The focus always goes back to the first column of the 1st tab page. Do u have any insight in this issue? I realize that this set up sucks, but I have no choice..It has already been set up this way (multiplle tabpages using the same dw) and I have to just work with it..

Commented:
Hallo gvijay1,

I did a small test and used the SetFocus() for datawindow and then SetColumn() for the column I wanted as current. (It worked without any error).

Datawindows name must not be the same overall in tabpages.

I do not know which form of datawindow you have. If it is a FreeForm then Datawindow must have only one row. If Datawindow is another form as grid or tabular then you should use the function GetRow() as well as Scrolltorow() function then the can show you the current column selected by setcolumn() function.

Please let me know, in which form build your datawindows.


Thanks

Bhatti
Commented:
On SelecTionChanged Event Of Tabpage Write a Following code
1. Set Focus on The datawindow using


datawindowname.SetFocus()
Precaution :If datawindowname is not declared as instace variable
Give full path
2.Set The specific row of datawindow
say 1 row
datawindowname.SetRow(1)
3.Set The specific Column of datawindow
say EmployeeName column
datawindowname.SetColumn('EmployeeName')
That's it

Author

Commented:
Bhatti,

Your solution worked. There was some issue with the datawindow and I had to manually set the tab order of the page first with the dw_test.Modify(Column.TabSequence="10") first before calling the SetColumn function.

How can I award this question to you. Thanks again for the help.

Commented:
Hi gvijay1,

I am happy to hear from you and that, the solution is working good. You also effort to solve it and my comments. It is realy diffucult to write how you should me award. I wrote that the effort was from both sides.
You can award with B grad. (To award is up to you how you understand my comments).

Bundles of thanks for your friendly comments.


THANKS


Bhatti

Commented:
Hallo gvijay1,

I think yesterday the experts-exchange was working properly. Now it is working I hope you have my comments. Thanks once again.


Bhatti

Commented:
Hallo gvijay1,

Sorry gvijay1,  I did not understand why you wrote me 10/22/2001 taht my solution is working good and you wanted to award me this question. Please write me few words to understand. THANKS


Bhatti