gpt4 book ai didi

c# - 关于在数据网格中保存列标题的问题!

转载 作者:行者123 更新时间:2023-11-30 18:43:24 26 4
gpt4 key购买 nike

当我更改数据网格中列的顺序时,这些设置会被保存,但它们不会在程序初始化时显示出来。为了显示保存的设置,我必须先从下拉框中选择另一个项目然后返回。然后显示保存的订单。我如何让该列在初始化时显示出来?

最佳答案

我不确定是否理解您的问题,但如果问题出在数据的结构顺序上,也许您可​​以在绑定(bind)之前订购数据网格的源集合(例如使用 LINQ)。对不起 VB,但我认为你可以轻松理解:

这是一个“紧凑”的例子:

Public Sub New()
' initialize the collection
_MyTypeItemList = From a In MyTypeItemList Select a Order By a.MyProperty2
End Sub

这是一个更完整的例子。如果这不是您需要的,请耐心等待,我是意大利人,我不是大师,我的英语也是如此:

Imports System.Collections.ObjectModel
Imports System.ComponentModel

Public Class MyType
Public Sub New()
' initialize the collection
_MyTypeItemList = From a In MyTypeItemList Select a Order By a.MyProperty2
End Sub

Private _MyTypeItemList As New ObservableCollection(Of MyTypeItem)

Public ReadOnly Property MyTypeItemList() As ObservableCollection(Of MyTypeItem)
Get
MyTypeItemList = _MyTypeItemList
End Get
End Property
End Class

Public Class MyTypeItem
Implements INotifyPropertyChanged

Public Sub New(ByVal MyProperty1Pass As Long, ByVal MyProperty2Pass As Date)
_MyProperty1 = MyProperty1Pass
_MyProperty2 = MyProperty2Pass
End Sub

Private _MyProperty1 As Long = Nothing
Private _MyProperty2 As Date = Nothing

Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

Public Property MyProperty1() As Long
Get
MyProperty1 = Me._MyProperty1
End Get

Set(ByVal value As Long)
If Not Object.Equals(Me._MyProperty1, value) Then
Me._MyProperty1 = value
Me.OnPropertyChanged("MyProperty1")
End If
End Set
End Property

Public Property MyProperty2() As Date
Get
Return Me._MyProperty2
End Get

Set(ByVal value As Date)
If Not Object.Equals(Me._MyProperty2, value) Then
Me._MyProperty2 = value
Me.OnPropertyChanged("MyProperty2")
End If
End Set
End Property

Protected Overridable Sub OnPropertyChanged(ByVal propertyName As String)
Dim handler As PropertyChangedEventHandler = Me.PropertyChangedEvent
If handler IsNot Nothing Then
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(propertyName))
End If
End Sub
End Class

关于c# - 关于在数据网格中保存列标题的问题!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4455550/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com