xsharp.eu • Assign databinding for a Textbox on WinForm, using the Properties Panel???
Page 1 of 1

Assign databinding for a Textbox on WinForm, using the Properties Panel???

Posted: Thu Mar 28, 2019 11:35 am
by Anonymous
I see a lot of code examples where a Textbox is used on a WinForm and the data binding to the Text property is always done in code using the DataBindings:Add() method.
pipmohciggakmbpm.png
pipmohciggakmbpm.png (14.51 KiB) Viewed 416 times
I'm wondering if it is possible to set this in the UI of the IDE in the Properties panel when you have a control selected in the Form Designer? (XIDE and VS)? Visual Studio indeed has the DataBinding properties available in Properties tab, but I could not get it to accept Self:SomeCustomFormProperty


In Visual FoxPro IDE, databing (ControlSource property) can be assigned in code also, but *many* VFP developers also use the IDE GUI to set ControlSource from the Form Designer, and I'll bet they will be hunting this feature in X# development experience one day.

See below a screenshot of how the FoxPro UI allows setting the "ControlSource" in a visual (that what VFP calls "data binding" for a Textbox).

Here is what it looks like in FoxPro:
moknihdnggjadnjm.png
moknihdnggjadnjm.png (108.28 KiB) Viewed 416 times
Here is what it looks like in Visual Studio:
2019-03-28_6-33-27.png
2019-03-28_6-33-27.png (96.25 KiB) Viewed 416 times

Assign databinding for a Textbox on WinForm, using the Properties Panel???

Posted: Thu Mar 28, 2019 12:00 pm
by wriedmann
Hi Matt,

the VO was way always a name based binding.

This works very well both in WPF and WinForms, when using own control classes.

You can find a sample for WinForms here:
https://riedmann.it/download/WinformsDa ... gApp.viaef
Wolfgang

Assign databinding for a Textbox on WinForm, using the Properties Panel???

Posted: Thu Mar 28, 2019 12:10 pm
by FoxProMatt
Yes, I have seen that example. However, there will be many cases when importing / translating exiting forms that did not use a naming convention.

Imagine a Container (GroupBox) on a form and inside the container is a Textbox, And imagine the oContainer has an oCustomer object on it. And the databinding for the TextBox is "This.Parent.oCustomer.cName"

Yes, I know it might be a little weird to databind one control to an object on another UI control, even an object on the parent container UI control, but such is the possibility in FoxPro, and believe me, many, many people do that in their apps (guilty me too).

Heck even "Thisform.oPurchaseOrder.oCusomtomer.oShippingDestination.cDestinationName"

Assign databinding for a Textbox on WinForm, using the Properties Panel???

Posted: Thu Mar 28, 2019 12:45 pm
by lumberjack
Hi Matt,
Not going to explain in detail, but here goes...
mattslay wrote: the container is a Textbox, And imagine the oContainer has an oCustomer object on it. And the databinding for the TextBox is "This.Parent.oCustomer.cName"
I have already studied that part of the VFP repo and know what has to be done:

Code: Select all

DELEGATE VFPContainer(blah blah blah) AS VFPContainerTyp
CLASS VFPForm INHERIT System.Windows.Forms.Form
    PROCTECT oContainer AS VFPContainer
    CONSTRUCTOR()
        SUPER()
        SELF:oContainer := ContainerBase
    RETURN
    PROPERTY Container AS VFPContainer GET SELF:oContainer SET SELF:oContainer := VALUE

    METHOD ContainerBase() AS VFPContainer
    RETURN
END CLASS
This the basics of how it work. Still have not got into the details, but if this is not working, I have already the INTERFACE concept also as a Plan B.

Code: Select all

CLASS VFPFormInt INHERIT Form IMPLEMENT IVFPFormContainer.
I know some will say but how this will work. Sorry let me first get my code done for it after we get the VFPRepo INTO X#, then this will become clear. Difficult to understand how I do it, but its a combination of Data-driven, Lexer, Compiler knowledge that I all throw together now... I will explain as we go along. Miss one of those concepts and it is way over your head.

Assign databinding for a Textbox on WinForm, using the Properties Panel???

Posted: Thu Mar 28, 2019 3:28 pm
by Chris
Matt, most probably the VFP window editor will be a dedicated custom editor (although not 100% certain about it yet) and we will make sure that you can edit such stuff exactly the way you are used to doing it already in the VFP IDE.

Yes, in the (WinForms) form designer in XIDE I have not implemented this, actually nobody has ever requested it, so I did not bother, since for my own needs I never use this method of handling data. In VS I think it should be already working though.