Databinding

Other topics

Remarks:

See https://msdn.microsoft.com/en-us/library/ef2xyb33.aspx Databinding only works with properties, never with fields!

Binding controls to data objects

Each control has a property DataBindings which is a list of System.Windows.Forms.Binding objects. The Add()-method has some overloads which enables you easily binding to the property of an object:

textBox.DataBindings.Add( "Text", dataObj, "MyProperty" );

Note, that binding basically means subscribing to each others changeevent. The code above subscribes to changeevent of dataObj.MyProperty and adapts textBox.Text when it changes. And vice versa it subscribes to textBox.TextChanged and adapts dataObj.MyPropery when it changes.

Parameters:

ArgumentDescription
propertyNameThe name of the control property to bind.
dataSourceAn Object representing the data source.
dataMemberThe property or list to bind to.
formattingEnabledDetermines, whether the displayed data should be formatted.
updateModeData source is updated when the control property is validated (default), or immediately when the property has changed
nullValueWhen the data source has this value, the bound property is set to DBNull.
formatStringOne or more format specifier characters that indicate how a value is to be displayed
formatInfoAn implementation of IFormatProvider to override default formatting behavior.

Contributors

Topic Id: 7362

Example Ids: 24425

This site is not affiliated with any of the contributors.