当我更改数据网格中列的顺序时,会保存这些设置,但在初始化程序时它们不会显示。为了显示保存的设置,我必须先从下拉框中选择另一个项目,然后返回。然后保存的订单显示出来。如何在初始化时显示列?
答案 0 :(得分:0)
进行更改后绑定数据网格吗?在asp.net中,至少你必须在修改gridview / datagrid后重新绑定以查看结果。
答案 1 :(得分:0)
我不确定是否提出了你的问题,但如果问题是数据的sturtup顺序,你可以在绑定之前订购datagrid的source-collection(例如使用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