Highlighted
Super Contributor.
Super Contributor.
1641 views

Binding Windows Form controls to a class as a data source

Jump to solution

I want to bind each control on my Windows Form to a property in a a class.  Is this possible ?

In C#, I can select a TextBox, expand its DataBindings node in the Properties window, click the arrow next to the Text property, then click on the "Add Project Data Source" link.  This link does not appear in Visual COBOL.  Even if the link did appear, I'm not even sure if I can use my class.  On the "Choose data source type" window, you can select "Object" but this doesn't seem to be what I am looking for.


I know how to do this in WPF using the download from this link:

http://community.microfocus.com/microfocus/cobol/visual_cobol/w/knowledge_base/19748.automatically-refresh-a-bound-wpf-control-when-values-of-bound-object-are-updated.aspx

Can I do something like this with a Windows Form ?

Phil Levin

Tags (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Binding Windows Form controls to a class as a data source

Jump to solution

Setting the binding through the GUI is not currently supported but you can set this up programmatically:

Here is a simple example that binds the Text property of a textbox control to a string property.

     $set ilusing"System.Windows.Forms"
      class-id testwinform.Form1 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      01 mystring   string  value "TEST" property.
      method-id NEW.
      procedure division.

          invoke self::InitializeComponent
          goback.

      end method.

      method-id button1_Click final private.
      procedure division using by value sender as object e as type System.EventArgs.
          invoke textBox1::DataBindings::Add(new type Binding("Text", self, "mystring"))
      end method.
      end class.

View solution in original post

0 Likes
3 Replies
Highlighted
Super Contributor.
Super Contributor.

RE: Binding Windows Form controls to a class as a data source

Jump to solution

We are using DevExpress for our user interface and they have a few things for me to try.  I'll let you know if that handles it.

Phil Levin

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Binding Windows Form controls to a class as a data source

Jump to solution

Setting the binding through the GUI is not currently supported but you can set this up programmatically:

Here is a simple example that binds the Text property of a textbox control to a string property.

     $set ilusing"System.Windows.Forms"
      class-id testwinform.Form1 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      01 mystring   string  value "TEST" property.
      method-id NEW.
      procedure division.

          invoke self::InitializeComponent
          goback.

      end method.

      method-id button1_Click final private.
      procedure division using by value sender as object e as type System.EventArgs.
          invoke textBox1::DataBindings::Add(new type Binding("Text", self, "mystring"))
      end method.
      end class.

View solution in original post

0 Likes
Highlighted
Super Contributor.
Super Contributor.

RE: Binding Windows Form controls to a class as a data source

Jump to solution

Thanks Chris.

Phil Levin

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.