System.Windows.Forms.ControlBindingsCollection.Remove(System.Windows.Forms.Binding)

Here are the examples of the csharp api class System.Windows.Forms.ControlBindingsCollection.Remove(System.Windows.Forms.Binding) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

5 Examples 7

1. Example

Project: magicaltrevor
Source File: Binder.cs
View license
protected IDisposable CreateBinding(Control c, string controlProperty, object source, string sourceProperty)
        {
            var binding = new Binding(controlProperty, source, sourceProperty);
            c.DataBindings.Add(binding);
            return Disposable.Create(() => c.DataBindings.Remove(binding));
        }

2. Example

Project: FieldLog
Source File: TxWinForms.cs
View license
public static void AddBinding(Control control, string propertyName, string key)
		{
			lock (controlBindings)
			{
				Dictionary<string, BindingData> propertyBindings;
				if (!controlBindings.TryGetValue(control, out propertyBindings))
				{
					// This is the first bound property for the control
					propertyBindings = new Dictionary<string, BindingData>();
					controlBindings.Add(control, propertyBindings);

					// Be notified when the control is disposed
					control.Disposed += Control_Disposed;
				}

				BindingData bindingData;
				if (propertyBindings.TryGetValue(propertyName, out bindingData))
				{
					// This property of the control is already bound, remove that first
					// Remove the binding from the control
					control.DataBindings.Remove(bindingData.Binding);

					// Dispose of the Tx binding instance
					bindingData.TxDictionaryBinding.Dispose();
				}

				// Add the new binding to the control and keep track of it
				TxDictionaryBinding db = new TxDictionaryBinding(key);
				bindingData = new BindingData(
					db,
					control.DataBindings.Add(propertyName, db, "Text"));
				propertyBindings[propertyName] = bindingData;
			}
		}

3. Example

Project: FieldLog
Source File: TxWinForms.cs
View license
public static void RemoveBinding(Control control, string propertyName)
		{
			lock (controlBindings)
			{
				Dictionary<string, BindingData> propertyBindings;
				if (controlBindings.TryGetValue(control, out propertyBindings))
				{
					BindingData bindingData;
					if (propertyBindings.TryGetValue(propertyName, out bindingData))
					{
						// Remove the binding from the control
						control.DataBindings.Remove(bindingData.Binding);

						// Dispose of the Tx binding instance
						bindingData.TxDictionaryBinding.Dispose();

						// Clean up internal structures
						propertyBindings.Remove(propertyName);
						if (controlBindings[control].Count == 0)
						{
							controlBindings.Remove(control);

							// Also remove the control Disposed handler with the last binding of this control
							control.Disposed -= Control_Disposed;
						}
					}
				}
			}
		}

4. Example

Project: TxTranslation
Source File: TxWinForms.cs
View license
public static void AddBinding(Control control, string propertyName, string key)
		{
			lock (controlBindings)
			{
				Dictionary<string, BindingData> propertyBindings;
				if (!controlBindings.TryGetValue(control, out propertyBindings))
				{
					// This is the first bound property for the control
					propertyBindings = new Dictionary<string, BindingData>();
					controlBindings.Add(control, propertyBindings);

					// Be notified when the control is disposed
					control.Disposed += Control_Disposed;
				}

				BindingData bindingData;
				if (propertyBindings.TryGetValue(propertyName, out bindingData))
				{
					// This property of the control is already bound, remove that first
					// Remove the binding from the control
					control.DataBindings.Remove(bindingData.Binding);

					// Dispose of the Tx binding instance
					bindingData.TxDictionaryBinding.Dispose();
				}

				// Add the new binding to the control and keep track of it
				TxDictionaryBinding db = new TxDictionaryBinding(key);
				bindingData = new BindingData(
					db,
					control.DataBindings.Add(propertyName, db, "Text"));
				propertyBindings[propertyName] = bindingData;
			}
		}

5. Example

Project: TxTranslation
Source File: TxWinForms.cs
View license
public static void RemoveBinding(Control control, string propertyName)
		{
			lock (controlBindings)
			{
				Dictionary<string, BindingData> propertyBindings;
				if (controlBindings.TryGetValue(control, out propertyBindings))
				{
					BindingData bindingData;
					if (propertyBindings.TryGetValue(propertyName, out bindingData))
					{
						// Remove the binding from the control
						control.DataBindings.Remove(bindingData.Binding);

						// Dispose of the Tx binding instance
						bindingData.TxDictionaryBinding.Dispose();

						// Clean up internal structures
						propertyBindings.Remove(propertyName);
						if (controlBindings[control].Count == 0)
						{
							controlBindings.Remove(control);

							// Also remove the control Disposed handler with the last binding of this control
							control.Disposed -= Control_Disposed;
						}
					}
				}
			}
		}