dotnet / dotnet/winforms

DataBindings: can't set formattingEnabled to false in designer

Open
#9,552 3 comments 0 reactions 1 assignee Claimed by @KlausLoeffelmann View on GitHub
area-VSDesigner
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### Environment

17.6.5

### .NET version

All up to 7.0

### Did this work in a previous version of Visual Studio and/or previous .NET release?

I think - no, 4.8 also checked.

### Issue description

Designer always add bindings with `formattingEnabled == true` you can't change this behavior even if "Format type" == "No formatting":
![image](https://github.com/dotnet/winforms/assets/17767561/3e8421be-d32d-40e0-a8df-8ed9442bb8f4)

Screen above will result in:
```cs
this.checkBox1.DataBindings.Add(new System.Windows.Forms.Binding("CheckState", this.paramsBindingSource, "checkState", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
```

More of it, if you manually change it to `false` in `Form1.Designer.cs` - any change in designer will revert it to `true`.
This is a critical bug for DataBindings. For example you can't bind to `CheckState` property of `CheckBox` with `formattingEnabled == true` - you will get error:
![image](https://github.com/dotnet/winforms/assets/17767561/581a91d0-cb44-442b-80fc-32d228717905)
Maybe this is other bug? 🤔
So for now we need to do such a bindings manually outside of `*.Designer.cs`... 😭

### Steps to reproduce

Build, run - try to click checkbox several times - you will see an error. If you change code in `Form1.Designer.cs` to:
```cs
this.checkBox1.DataBindings.Add(new System.Windows.Forms.Binding("CheckState", this.paramsBindingSource, "checkState", false, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
```
all will be ok.
[DataBindingsFormatBug.zip](https://github.com/dotnet/winforms/files/12144624/DataBindingsFormatBug.zip)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.