Databinding to a ToolStripStatusLabel

Hi,
Why there is no databindings for ToolStripStatusLabel? I need to add a databinding to it, like a regular label allows databinding for its text. I know StatusStrip can be databinded, but I cannot use this solution (I need a StatusStrip with 3 labels, each of them databinded to different properties).
Regards,
Valentin Iliescu
[346 byte] By [viliescu] at [2008-2-7]
# 1

This is not supported directly - you'll need to sub-class a ToolStripStatusLabel and make it an IBindableComponent (sample below). You'll then need to manually add the Bindings.

Joe


[ToolStripItemDesignerAvailability(ToolStripItemDesignerAvailability.StatusStrip)]
public class BindableToolStripStatusLabel : ToolStripStatusLabel, IBindableComponent
{
private BindingContext _context = null;

public BindingContext BindingContext
{
get
{
if (null == _context)
{
_context = new BindingContext();
}

return _context;
}
set { _context = value; }
}

private ControlBindingsCollection _bindings;

public ControlBindingsCollection DataBindings
{
get
{
if (null == _bindings)
{
_bindings = new ControlBindingsCollection(this);
}
return _bindings;
}
set { _bindings = value; }
}
}

JoeStegman at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2
This solution is useful to my project and I have implemented it in VB as below but, although I have matched the property signatures I am still getting these errors:

"Error 1 Class 'BindableToolStripStatusLabel' must implement 'Property BindingContext() As BindingContext' for interface 'System.Windows.Forms.IBindableComponent'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers. "

"Error 2 Class 'BindableToolStripStatusLabel' must implement 'ReadOnly Property DataBindings() As ControlBindingsCollection' for interface 'System.Windows.Forms.IBindableComponent'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers."

What am I doing wrong?

Public Class BindableToolStripStatusLabel
Inherits ToolStripStatusLabel
Implements IBindableComponent

Private _context As BindingContext = Nothing
Private _bindings As ControlBindingsCollection

Public Property BindingContext() As BindingContext
Get
If Nothing Is _context Then
_context = New BindingContext()
End If
Return _context
End Get
Set(ByVal value As BindingContext)
_context = value
End Set
End Property

Public ReadOnly Property DataBindings() As ControlBindingsCollection
Get
If _bindings Is Nothing Then
_bindings = New ControlBindingsCollection(Me)
End If
Return _bindings
End Get
End Property

End Class

MarkJ. at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 3
Correct VB solution:

Public Class BindableToolStripStatusLabel
Inherits ToolStripStatusLabel
Implements IBindableComponent


Private _context As BindingContext = Nothing
Private _bindings As ControlBindingsCollection

Public Property BindingContext() As BindingContext Implements IBindableComponent.BindingContext
Get
If _context Is Nothing Then
_context = New BindingContext()
End If
Return _context
End Get
Set(ByVal value As BindingContext)
_context = value
End Set
End Property

Public ReadOnly Property DataBindings() As ControlBindingsCollection Implements IBindableComponent.DataBindings
Get
If _bindings Is Nothing Then
_bindings = New ControlBindingsCollection(Me)
End If
Return _bindings
End Get
End Property

End Class

MarkJ. at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...