-
Yes Problem description:
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
We had a similar problem for years in our app, which I think is caused by the same limitation. The StatusStrip does not supports binding because the method We fixed this problem by subclassing StatusStrip and adding a specific method to update the BindingContext on all toolstrip item by overriding OnBindingContextChanged. For a more general fix, the StatusStrip (and Toolstrip) should override OnBindingContextChanged and update the binding context on all child items, because the base Control.OnBindingContextChanged will not. This code also need to explore all ToolStripItem children. |
Beta Was this translation helpful? Give feedback.
-
How should I rewrite it? I don't know much about the "BindingContext" of the component,Manually call onbindingcontextchanged of toolstripitem? |
Beta Was this translation helpful? Give feedback.
-
This prevents access to protected members, --> CS1540
|
Beta Was this translation helpful? Give feedback.
-
It's an old problem and I don't remember exactly the details. We also add to subclass the StatusStripItem if I remember. There is no easy fix. And by reviewing your code, I see that you are setting directly the DataSource on the control, so I am not even sure my comment applies to your problem. In our case, the DataSource was a BindingSource component attached to the parent form. You should try creating a new empty BindingContext and attach it to your control, or simply set the BindingContext of the toolstripcontrolhost? In our case it was related to this. |
Beta Was this translation helpful? Give feedback.
-
Thank you,
|
Beta Was this translation helpful? Give feedback.
-
You need to assign a binding context to the hosted control, otherwise a currency manager object isn't created: winforms/src/System.Windows.Forms/src/System/Windows/Forms/ListControl.cs Lines 690 to 710 in 40dd779 box = new ListBox()
{
Margin = Padding.Empty,
Dock = DockStyle.Fill,
SelectionMode = SelectionMode.MultiSimple
};
box.DisplayMember = "Text";
box.ValueMember = "Value";
box.DataSource = new ObservableCollection<TestItem>(
Enumerable.Range(1, 10).Select(i => i.ToString())
.Select(i => new TestItem() { Text = i, Value = i })
);
box.BindingContext = this.BindingContext; // <<-- fix
host = new(box) { Padding = Padding.Empty, Margin = Padding.Empty };
_dropDown.Items.Add(host); Admittedly I had to step through the code and search the internet myself. In essence here's the answer https://stackoverflow.com/a/3481908/2338036. Because this is a long standing behaviour changing it carries a significant compat risk, and with such a simple workaround it is unlikely we'll be changing it. |
Beta Was this translation helpful? Give feedback.
You need to assign a binding context to the hosted control, otherwise a currency manager object isn't created:
winforms/src/System.Windows.Forms/src/System/Windows/Forms/ListControl.cs
Lines 690 to 710 in 40dd779