Click here to Skip to main content
15,893,790 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: Remote connection in SqlServer with C# Pin
Ashfield26-Oct-09 22:16
Ashfield26-Oct-09 22:16 
AnswerRe: Remote connection in SqlServer with C# Pin
dan!sh 27-Oct-09 2:19
professional dan!sh 27-Oct-09 2:19 
QuestionRead email from exchange server Pin
nitin_ion26-Oct-09 21:53
nitin_ion26-Oct-09 21:53 
AnswerRe: Read email from exchange server Pin
Ashfield26-Oct-09 22:18
Ashfield26-Oct-09 22:18 
GeneralRe: Read email from exchange server Pin
Archimedes2428-Oct-09 0:55
professionalArchimedes2428-Oct-09 0:55 
GeneralRe: Read email from exchange server Pin
εїзεїзεїз15-Feb-10 1:45
εїзεїзεїз15-Feb-10 1:45 
GeneralRe: Read email from exchange server Pin
Ashfield15-Feb-10 3:15
Ashfield15-Feb-10 3:15 
QuestionReference to parent collection Pin
ausadmin26-Oct-09 19:27
ausadmin26-Oct-09 19:27 
Apologies in advance, I suspect there may be an obvious answer to this, but I have searched these forums and google and not really been able to determine the solution.

This is for a WPF application, but I think it is a more general programming question.

We have an ObservableCollection(of T), where we need do do some validation of the member object, T. One of the rules is that a property of T (say name) cannot already exist in the collection.

Our validation class is instantiated from the xaml, so I don't know of any way to pass in the reference to the ObservableCollection. However, this is needed to be able to step through the collection, to see if name has already been used, and report an error (if needed).

One solution I can see is that the class T could have a property which is an ObservableCollection of T, and then you pass the parent collection into the member object. I think this will solve the issues, but something says to me this would be bad practise... Can anyone clarify whether this will cause errors or should be avoided? Can anyone suggest an alternative?

More specifically, say we define Person
Public Class Person
    Public Sub New(ByVal Name As String, ByVal People As ObservableCollection(Of Person))
        ...
    End Sub

    Public Property Name() As String
        ...
    End Property

    Public Property People() As ObservableCollection(Of Person)
        ...
    End Property
End Class


Then elsewhere make a collection of Person
Dim MemberList As New ObservableCollection(Of Person)
MemberList.Add(New Person("John", MemberList))
MemberList.Add(New Person("Fred", MemberList))
MemberList.Add(New Person("Jane", MemberList))
MemberList.Add(New Person("Andrew", MemberList))


Then we can bind say a WPF DataGrid to MemberList, and use validation to check our rule, to check that the Person name has not already been used in the ObservableCollection(of Person) - ie MemberList. The approach here will work, but I am concerned that there might be underlying problems - some circular reference or something (or else just not good practise).

Thanks for any suggestions.

Tim

modified on Tuesday, October 27, 2009 1:40 AM

AnswerRe: Reference to parent collection Pin
Dave Kreskowiak27-Oct-09 3:24
mveDave Kreskowiak27-Oct-09 3:24 
GeneralRe: Reference to parent collection Pin
ausadmin27-Oct-09 9:15
ausadmin27-Oct-09 9:15 
GeneralRe: Reference to parent collection Pin
Dave Kreskowiak27-Oct-09 10:47
mveDave Kreskowiak27-Oct-09 10:47 
Questionvb.net and plc Pin
stepdeb26-Oct-09 15:48
stepdeb26-Oct-09 15:48 
AnswerRe: vb.net and plc Pin
Luc Pattyn26-Oct-09 15:58
sitebuilderLuc Pattyn26-Oct-09 15:58 
AnswerRe: vb.net and plc Pin
Andy_L_J26-Oct-09 20:46
Andy_L_J26-Oct-09 20:46 
QuestionMaking my program run another program Pin
Sezotove26-Oct-09 12:05
Sezotove26-Oct-09 12:05 
AnswerRe: Making my program run another program Pin
Henry Minute26-Oct-09 12:11
Henry Minute26-Oct-09 12:11 
GeneralRe: Making my program run another program Pin
Sezotove26-Oct-09 12:13
Sezotove26-Oct-09 12:13 
AnswerRe: Making my program run another program Pin
Shameel27-Oct-09 0:28
professionalShameel27-Oct-09 0:28 
AnswerRun a program on another computer ... Pin
David Mujica27-Oct-09 3:21
David Mujica27-Oct-09 3:21 
QuestionLoad special txt File in TreeView [modified] Pin
Carsten Schafflhuber26-Oct-09 10:44
Carsten Schafflhuber26-Oct-09 10:44 
AnswerRe: Load special txt File in TreeView Pin
Christian Graus26-Oct-09 11:00
protectorChristian Graus26-Oct-09 11:00 
GeneralRe: Load special txt File in TreeView Pin
Carsten Schafflhuber26-Oct-09 11:06
Carsten Schafflhuber26-Oct-09 11:06 
GeneralRe: Load special txt File in TreeView Pin
Christian Graus26-Oct-09 12:11
protectorChristian Graus26-Oct-09 12:11 
QuestionRemoving a split container Pin
procreator26-Oct-09 10:22
procreator26-Oct-09 10:22 
AnswerRe: Removing a split container Pin
Henry Minute26-Oct-09 12:16
Henry Minute26-Oct-09 12:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.