Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

[IronPython] How to processing two way DataBinding String TextBox.Text?

$
0
0

Greetings.

Here is a code

import clr

clr.AddReference("System")
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.ComponentModel")

from System import *
from System.Drawing import *
from System.Windows.Forms import *
from System.ComponentModel import *


class StringWithBinding(INotifyPropertyChanged):

    def __init__(self, aValue):

        self._mValue = aValue

    def get_Value(self):

        return self._mValue

    def set_Value(self, value):

        self._mValue = value
        self.OnPropertyChanged("Value")

    Value = property(fget=get_Value, fset=set_Value)

    def OnPropertyChanged(self, aName):

        if PropertyChanged is not None:

            self.PropertyChanged(self, PropertyChangedEventArgs(aName))


class Program(Form):

    def __init__(self):

        super(Program, self).__init__()

        self.str = StringWithBinding("A")

        tab = TableLayoutPanel()
        tab.Parent = self
        tab.ColumnCount = 1
        tab.Dock = DockStyle.Fill
        tab.Padding = Padding(self.Font.Height)

        text = TextBox()
        text.Parent = tab
        text.DataBindings.Add("Text", self.str, "Value")#,
             #False, DataSourceUpdateMode.OnPropertyChanged)

        button = Button()
        button.Parent = tab
        button.Text = "Go!"
        button.Click += self.OnButtonClick

    def OnButtonClick(self, aSender, aEa):

        Console.WriteLine(self.str.Value)


if __name__ == '__main__':

    form = Program()
    Application.Run(form)

Well with comment 3 and 4 parameters this one way Data Binding but even now app freezing after some input pass to text box.

When 3 and 4 parameters uncomment after pass some input in text box I got JIT error message "global name 'PropertyChanged' is not definined."

How to change code to resolve this problem?

Thanks.

P.S.

Code for StringWithDataBinding take (after change and translate) from C# sample -http://stackoverflow.com/a/9148341



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>