BindingList FindCore, how do you implement this? Why doesn't this not work?

C

Chad Dokmanovich

If you could answer this, I would be very appreciative:


Why does this code die on line 63 with the error "Specified method is not supported." error message?



1 Imports System.ComponentModel

2

3 Public Enum DataType As Integer

4 [String] = 0

5 [Integer] = 1

6 [Date] = 2

7 End Enum

8

9 Public Class SessionStateValue

10

11 Private _KeyName As String

12 Private _DataType As DataType

13 Private _KeyValue As Object

14

15 Public Sub New(ByVal keyName As String, _

16 ByVal dataType As DataType, _

17 ByVal keyValue As Object)

18

19 _KeyName = keyName

20 dataType = dataType

21 _KeyValue = keyValue

22

23 End Sub

24

25 Public ReadOnly Property KeyName() As String

26 Get

27 Return _KeyName

28 End Get

29 End Property

30

31 Public readonly Property DataType() As DataType

32 Get

33 Return _DataType

34 End Get

35 End Property

36

37 Public Property KeyValue() As Object

38 Get

39 Return _KeyValue

40 End Get

41 Set(ByVal value As Object)

42 _KeyValue = value

43 End Set

44 End Property

45

46 End Class

47

48 Public Class SessionStateValues

49

50 Inherits System.ComponentModel.BindingList(Of SessionStateValue)

51

52 Protected Overrides ReadOnly Property SupportsSearchingCore() As Boolean 'I thought this would fix the problem

53 Get

54 Return True

55 End Get

56 End Property

57

58 Public Function ItemByKeyName(ByVal keyName As String) As SessionStateValue

59

60 Dim Ordinal As Integer

61 Dim Properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(GetType(SessionStateValue))

62

63 Ordinal = MyBase.FindCore(Properties.Item("KeyName"), keyName)

64

65 Dim SessionStateValue As SessionStateValue = Me.Items(Ordinal)

66

67 Return SessionStateValue

68

69 End Function

70

71 End Class

72

73 Public Class SessionState

74

75 Private _SessionId As String

76 Private _SessionStateValues As SessionStateValues

77

78 Public Sub New(ByVal sessionId As String)

79 _SessionId = sessionId

80 _SessionStateValues = New SessionStateValues

81 End Sub

82

83 Public ReadOnly Property SessionId() As String

84 Get

85 Return _SessionId

86 End Get

87 End Property

88

89 Public ReadOnly Property SessionStateValues() As SessionStateValues

90 Get

91 Return _SessionStateValues

92 End Get

93 End Property

94

95 End Class



'Here's where I use the above objects:

1

2

3 Public Class Form1

4

5 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

6

7 End Sub

8

9 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

10

11 Dim SessionState As New SessionState("eqwerre233214")

12

13 SessionState.SessionStateValues.Add(New SessionStateValue("UserName", DataType.String, "Chad"))

14 Dim SessionStateValue As SessionStateValue = SessionState.SessionStateValues.ItemByKeyName("UserName") '<----Dies "inside" this call

15

16 End Sub

17 End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top