Windows窗体:DataGridView的问题用的backgroundColor排序后窗体、问题、Windows、backgroundColor

2023-09-07 08:41:56 作者:生死皆闲事

我有一个的Windows窗体DataGridView ,其中的行有不同的背景颜色。

I have a Windows Forms datagridview, where the rows have different background-colors.

现在的问题是,之后的背景颜色消失的排序(点击行标题)和所有行又白(默认颜色)。可能是什么这个问题的原因是什么?

The problem is, that the background-colors disappear after sorting (click on a row header) and all rows are again white (default color). What could be the reason for this problem?

推荐答案

根据这个bug 2005年6月提交给Microsoft的报告这是由设计的Visual Studio 2005:

According to this bug report submitted to Microsoft on June 2005 this is by design for Visual Studio 2005:

感谢您的错误报告。该   你注意到的行为是由设计。   排序数据绑定网格导致所有   行重新创建(称为   ListChangedType.Reset)。这将导致   您格式化丢失。你需要   使用DataBindingComplete事件   应用样式并检查   ListChangedType.Reset知道什么时候   运用你的造型。另外,您   可以使用CellFormatting事件。   理想的情况是所有格式可   由于CellFormatting内部完成   它是动态应用。

Thank you for your bug report. The behavior you notice is by design. Sorting a databound grid causes all rows to be recreated (called a ListChangedType.Reset). This causes your formatting to be lost. You need to use the DataBindingComplete event to apply styles and check for the ListChangedType.Reset to know when to apply your styling. Alternatively you can use the CellFormatting event. Ideally all your formatting can be done inside the CellFormatting since it is applied dynamically.