Comments (3)
@Tanya-Solyanik The core of the problem lies in the immutable nature of ImmutableArray
. WinForms data binding mechanisms require collections that support change notifications to properly propagate changes between the UI and the data source. ImmutableArray
does not support these notifications, leading to the observed behavior.
Also, defining Value1
as IReadOnlyList
, as it is done in the minimal reproducible example provided by the author, might give the illusion of immutability, but due to its access level being set to public, it can be modified from outside the class, which is not the case with ImmutableArray
.
Workaround:
For data binding scenarios in WinForms, it is advisable to use ObservableCollection
or BindingList
. These collections are mutable and, therefore, support the two-way data binding required by WinForms.
Here is a modified snippet of MainModel.cs
, from the sample code, demonstrating how to adapt the existing code to use ObservableCollection<int>
instead of ImmutableArray
for Values2
:
public ObservableCollection<int> Values2 { get; }
public MainModel()
{
var values = new[] { 1, 2, 3 };
Values1 = values.ToImmutableArray();
Values2 = new ObservableCollection<int>(values);
}
This approach ensures that the ComboBox
can properly interact with the data source and maintain its state across UI interactions.
from winforms.
@Olina-Zhang can your team please test?
Related StackOverflow post:
https://stackoverflow.com/questions/8940675/c-sharp-combobox-selectedvalue-gets-reset-on-focus-lost/
from winforms.
@elachlan
The issue can reproduce on both .NET Framework from 4.6 - 4.8.1 and .NET from 6.0 - 9.0.
from winforms.
Related Issues (20)
- [Tracking]
- Hope to provide the ability to customize the title bar HOT 4
- [dnceng-bot] Branch `winforms/release/6.0` can't be merged to Azdo internal branch HOT 1
- [dnceng-bot] Branch `winforms/release/8.0` can't be merged to Azdo internal branch HOT 1
- The "span multiple rows or columns" and "align a control" links are not working in the DemoConsole application HOT 2
- TrackBar visually breaks with certain changes to certain properties HOT 4
- System.NullReferenceException: 'Object reference not set to an instance of an object.' occurs when click the help button in TreeView smarttag in the DemoConsole application HOT 5
- Unable to switch the tabs using mouse. Only switching the tab can be done through TabKey navigation at DesignTime HOT 5
- Can't Bind a Custom IBindingList Component to Controls at DesignTime in .NET 8 HOT 5
- Microsoft.DotNet.DesignTools.Client.DesignToolsServerException: Could not resolve type, 'System.ComponentModel.ComponentEditor HOT 2
- ObjectSelectorEditor,Selector,SelectorNode types are not available in the System.ComponentModel.Design namespace in .NetCore projects in WinForms HOT 6
- Undo in DemoConsole clears all item in ListView instead of undo previous move HOT 2
- InvalidOperationException thrown when calling OnItemChecked in class derived from ListView (in VirtualMode) HOT 11
- Unhandled exception has occurred when deleting ListView with setting its VirtualMode and VirtualListSize HOT 1
- In .NetCore project, Changes made in the Designer not being Serialized in the Designer.cs file. HOT 2
- Missing instances of designers in the DemoConsoleApp
- Refactor `lock` on `object` usage to `System.Threading.Lock` HOT 5
- The comboBox incorrect display when setting its DropDownStyle as Simple in the DemoConsole application HOT 1
- LinkLabel image display abnormally HOT 2
- Confusing Error Message Surfaces During Clipboard Operation HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from winforms.