Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture last grid column before new left-mouseclick

Status
Not open for further replies.

koklimabc

Programmer
Jun 17, 2013
49
MY
Hi all,

I'm having problem to capture last grid's column (identified as number) after new left-mouseclick other column's.

Let said I obtain column 3 from first setfocus of column 3 (column's cell selection) and I proceed to left-mouselick on columns 4.
It would return as 4 but doesn't match to what i need is 3.How could I suppose to get 3.

Code in Form

public precolumn

with thisform.grid_list

.addobject("column2","column")
.columns(2).visible = .t.
.columns(2).width = 55
.columns(2).header1.alignment = 2
.columns(2).header1.caption = "Supcode"
.columns(2).removeobject("text1")
.columns(2).addobject("text1","text_")
.columns(2).text1.visible = .t.
.columns(2).sparse = .t.

endwith


Code in main.prg

define class text_ as textbox
borderstyle = 0

procedure mousedown
LPARAMETERS nButton, nShift, nXCoord, nYCoord

curcontrol = _screen.activeform.activecontrol
curcolumn = curcontrol.activecolumn
messagebox("check column(beforepress):" + trans(precolumn)) =>It suppose return 3(column number3),but it just give 4(new left mouseclick on column's cell)
=>I want to get 3 instead of 4.

endpro

procedure gotfocus ** (Capture and stored column in public variable for later comparison in next mouse-click event) **
precontrol = _screen.activeform.activecontrol
precolumn = precontrol.activecolumn

endpro

enddefine


Thanks Appopriate to anyone answers and helps.
 
>It would return as 4 but doesn't match to what i need is 3.How could I suppose to get 3.
I don't follow your thought here.

If a mouse click on column 4 should not be allowed, make the column readonly. The best way to do so is add RETURN .F. in the columns control WHEN event.
If you want to know which column will be or was activated take a look at the BEFOREROWCOLCHANGE and AFTERROWCOLCHANGE events of the grid.

Bye, Olaf.
 
Okay, Thanks to your 1st reply.

I've question and would you mind elaborate more example in "The best way to do so is add RETURN .F. in the columns control WHEN event." to further guide me? Thanks.
 
Well, in the form designer drill down to text1 of the column4 and there edit the WHEN event. Put in RETURN .F.

Bye, Olaf.
 
I'm also confused about what you are trying to achieve. Are you saying you don't want to let the user click on col 4 at all? And if not, why not?

Do you want to disallow editing of column 4, as Olaf suggested? If so, preventing a mouse click won't achieve that. You would have to make the column completely read-only. Either follow Olaf's suggestion regarding the When event, or set the column's ReadOnly to .T.

But I think you need to clarify what you are trying to do.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Readonly of the columns is another option, but the click on a read only column takes some time before rejection for some reason. The when event is the cleaner solution. It requires the grid design to be at design time, eg your form can't have an empty grid and you set the rowsourde (or is it recordsource, I always confuse which controls have what) at runtime, you can't put code into objects created at runtime, unless you change something called member classes, which determines which column object is added to the grid and which control is added to each column. That just leads very far off.

Bye, Olaf.

 
Olaf, I agree that the When event is a better solution. I just wanted to make it as simple as possible. Of course, we are still guessing at what he is tryting to achieve.

Koklimabc, I expect that the reason you are seeing the wrong column number is that you are adding a column dynamically after the grid has been instantiated and populated. Do you have some particular reason for doing that? And why exactly do you need to know which column has been clicked?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top