Selezione con il mouse

Forum dedicato ai programmatori di X# in lingua italiana – Italian language forum

Moderator: wriedmann

User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

Selezione con il mouse

Post by Gfb22 »

Domanda sicuramente ...banale.
In una DataBrowser come quella dell'esempio cosa devo fare per poter scegliere il record evidenziato con il doppio click del mouse in alternativa alla scelta con il Default Button?
Grazie per i suggerimenti...
scelta.jpg
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Re: Selezione con il mouse

Post by FFF »

Your Defaultbutton has the code to return the complete record?
Pseudocode:
GfBBrowser inherit Databrowser
Method MouseButtonDoubleclick(..)
Super: Method MouseButtonDoubleclick(..)
Self:Owner:yourButtonname
...
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

Re: Selezione con il mouse

Post by Gfb22 »

Hi Karl,
this is the code (ButtonOk is the default button) but when you double click nothing happens.
What did I forget?
Thank you!
Gfb

Code: Select all

method MouseButtonDoubleClick(oMouseEvent) class ScegliSchBrowse
	local nButtonID as int
	nButtonID := IIf(oMouseEvent == NULL_OBJECT, 0, oMouseEvent:ButtonID)
	super:MouseButtonDoubleClick(oMouseEvent)
	//Put your changes here
	self:Owner:ButtonOK() // Return choice code to the Owner
	return nil
gfb
User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

Re: Selezione con il mouse

Post by Gfb22 »

Hi all!
Riprendo X# dopo alcuni mesi in cui ho fatto altro.
In una dataBrowse non riesco a selezionare un record usando DoubleClick.
Di seguito il mio codice, sia con ButtonDoubleClick() che con MouseButtonDoubleClick(), come di seguito.

Code: Select all

method ButtonDoubleClick(oControlEvent) class StdDataWindow
	local oControl as Control
	LOCAL oTB as TextBox
	oControl := iif(oControlEvent == null_object, null_object, oControlEvent:Control)
	super:ButtonDoubleClick(oControlEvent)
	//Put your changes here
	self:Owner:ViewRecord()
	return nil

method MouseButtonDoubleClick(oMouseEvent) class StdDataWindow
	local nButtonID as int
	LOCAL oTB as TextBox

	nButtonID := iif(oMouseEvent == null_object, 0, oMouseEvent:ButtonID)
	super:MouseButtonDoubleClick(oMouseEvent)
	//Put your changes here
	self:Owner:ViewRecord()
	return nil

METHOD ViewRecord() CLASS StandardShellWindow
	LOCAL oTB as TextBox
		oTB := TextBox{self, "View record", "Record n. " + NTrim(self:oNewChild:Server:RECNO)}
		oTB:Type := BUTTONOKAY
		oTB:Show()
RETURN nil
Per capire meglio cosa sbaglio allego un piccolo AEF di esempio.
Grazie per ogni suggerimento: certamente c'è qualcosa che manca...
Gfb
Attachments
Test-DoubleClick.zip
(9.86 KiB) Downloaded 162 times
gfb
User avatar
Chris
Posts: 4899
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Re: Selezione con il mouse

Post by Chris »

Hi Gian,

Unfortunately due to the way the VOSDK and the DataBrowser is designed, you need to trap this at the browser level, in a subclass. Create one like this:

Code: Select all

CLASS ParentDataBrowser INHERIT DataBrowser
METHOD CellDoubleClick() CLASS ParentDataBrowser
IF IsMethod(SELF:Owner,#SubFormCellDoubleClick)
	Send(SELF:Owner,#SubFormCellDoubleClick)
END IF
RETURN NIL
and then in the Init() of your StdDataWindow add this just after the SUPER:Init() call, in order to tell it to create the databrowser using your new class:

Code: Select all

SUPER:Init(oParentWindow)
SELF:BrowserClass := #ParentDataBrowser
then, you can define a method in the window to do what you want:

Code: Select all

METHOD SubFormCellDoubleClick() CLASS StdDataWindow
SELF:Owner:ViewRecord()
RETURN NIL
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

Re: Selezione con il mouse

Post by Gfb22 »

Hi Chris,
thanks for your time!
In VO it works well; in XIDE it gives me this error:
error.jpg
and this is the line of code that generates the error (line 54):

Code: Select all

SELF:oNewChild:ViewAs(#BrowseView)
and this is the DoOpenFile() method

Code: Select all

METHOD DoOpenFile(cFileName, lReadOnly, cIndex) 
	LOCAL oTB AS TextBox
	IF (Len(cFileName) > 3 )  .AND. (Upper(Right(cFileName, 4)) == ".DBF")
		SELF:oNewChild := StdDataWindow{SELF, cFileName, lReadOnly}
		SELF:oNewChild:ViewAs(#BrowseView)
// Imposta ReadOnly
		SELF:oNewChild:Browser:SetStandardStyle(gbsReadOnly)
		SELF:oNewChild:Show(SHOWCENTERED)
	ELSE
		oTB := TextBox{SELF, "File Open Error", "Cannot open " + cFileName + " - Not a DBF file"}
		oTB:Type := BUTTONOKAY
		oTB:Show()
	ENDIF
	RETURN SELF		
Thanks for the tips
gfb
gfb
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Selezione con il mouse

Post by robert »

Gian,
Add a constructor to the class

Code: Select all

CLASS ParentDataBrowser INHERIT DataBrowser
CONSTRUCTOR(oOwner, xID, oPoint, oDimension)
SUPER(oWin, xID, oPoint, oDimension)
RETURN

METHOD CellDoubleClick() CLASS ParentDataBrowser
IF IsMethod(SELF:Owner,#SubFormCellDoubleClick)
	Send(SELF:Owner,#SubFormCellDoubleClick)
END IF
RETURN NIL
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

Re: Selezione con il mouse

Post by Gfb22 »

Thanks Robert,
but the error is the same on the line:

Code: Select all

SELF:oNewChild:ViewAs(#BrowseView)
gfb
gfb
User avatar
robert
Posts: 4518
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Re: Selezione con il mouse

Post by robert »

If you remove the line

Code: Select all

SELF:BrowserClass := #ParentDataBrowser
then the browser opens?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Gfb22
Posts: 105
Joined: Sat Oct 08, 2022 7:43 pm
Location: Italy

Re: Selezione con il mouse

Post by Gfb22 »

If I remove the line:

Code: Select all

SELF:BrowserClass := #ParentDataBrowser
there is a new error:
"..description : No exported method 'SETSTANDARDSTYLE'
Subsystem : BASE
GenCode : EG_NOMETHOD No exported method
"
at line:

Code: Select all

SELF:oNewChild:Browser:SetStandardStyle(gbsReadOnly)
.
If I remove this line too, the browser opens but Double Click doesn't work...
gfb
gfb
Post Reply