Validate Items Of A .NET Collection Against Each-other?
Dec 2, 2011
I have a class that represents some business object, such as this:
Public Class MyObject
Inherits SomeBaseObject ' Implements INotifyPropertyChanged and IDataErrorInfo
Private mMyVariable as Integer
Public Property MyVariable as Integer
[code]....
SomeBaseObject implements both INotifyPropertyChanged and IDataErrorInfo, such that a Validate method will populate the appropriate IDataErrorInfo fields when setting the property values.I also have a collection that supports change events, which I eventually bind to a WPF DataGrid.
Public Class MyCollection
Inherits ObservableCollection(Of MyObject)
End Class
Part 1: Let's say that I have a business rule which says that no two items in my collection may have the same value for MyVariable. How do I set up my events (or implement additional interfaces somewhere) to perform this cross-item validation whenever the property value changes on any item in the collection?
Part 2: Suppose I have a list of integers such that whenever I add a new MyObject item to an instance of MyCollection or change the MyVariable property on any item already in the collection, the value of the MyVariable property must exist in this list of integers?
View 1 Replies
ADVERTISEMENT
Apr 6, 2012
currently in my application I have a Global Collection that is a Collection of Collections.Currently I am trying to add items/ elements to one of the child collections of the Global Collection but I am unable to use the collections methods of the child.When I assign a variable to the child collection and return the collection it is just an object with the collection inside.
Ex:
Dim GlobalCollection as New Collection
Dim ChildCollection1 as New Collection
Dim tempCurrentCollection[code]......
View 3 Replies
Mar 28, 2009
i created a validation procedure on a textbox_validating event. the procedure goes something like [Code] but somehow it doesn't stop the system from continuing. what happens is on my Save Button where i have. [Code] i'm assuming that when i click the save button, the Textbox1_Validating event is also fired since it also brings up the MessageBox. but then after pressing OK on the MessageBox, it continues to try and Update the DataTable where I get an error from the database saying that the Column does not allow null values.
also when i click Save Button, i noticed that the Textbox1_Validating Event is only fired when the cursor is on that item. basing from this, it seems that the not all Validating Events are fired when an Adapter.Update is executed. what's the best way to validate items? should it be on the Save Button and not on the Validating event of each items?
View 14 Replies
Apr 13, 2011
Aren't arrays of object enumerable?Look for the comments in the code
Public Class AddressCollection
Inherits System.Collections.ObjectModel.Collection(Of AddressType)
Public Sub New()
End Sub
[Code]...
View 3 Replies
Apr 11, 2012
I have a simple subroutine that loads a list from a database. I would like to be able to use the same code to load a ListBox and a ComboBox by defining the list type as the common abstract base class ListControl, and see no reason why I can't - except that VB.NET doesn't expose/implement/whatever the Items collection in ListControl. I note with frustration that this is not the case in ASP.NET. At moment my code is ugly because I have to check what type of list control I have passed in, in order to cast it to a type that has an Items collection. (My code may be ugly for numerous other reasons too, but it is beautiful to me). Is there a way to rewrite the code to avoid having to go through the testing and casting nonsense? (I've stripped it down somewhat so that all that remains is where the problem lies).
Sub loadList(ByVal db As SqlDatabase, ByVal strCommandText As String, lstHost As ListControl, Optional bClearList As Boolean = True, Optional bIsListBox As Boolean = True)
If bClearList Then
[code]....
View 1 Replies
Mar 1, 2010
i am trying to sort the items in a collection(of T), by the start date. but i do not know how to do it. i do know that we have to implement list properties.
View 2 Replies
Apr 18, 2011
I often have a class defined and I also define another class that is simply a collection of the other class. To do this I found it easiest just to define the other class as Inherits List(Of Type). The reason I define a collection class is to add extra functionality to the collection. Take the following code for example.
Class Car
Property Name As String
Property Year As Short
[Code]....
how can I define my own collection so that I can reference it by index or name like that. Right now I can only reference it by index.
View 5 Replies
Oct 20, 2009
removal of items in a collection or list using the " For Each " statement to iterate through.This code works:
For Each item As ListViewItem In ListView1.SelectedItems
ListView1.Items.Remove(item)
Next
This code does not:
For Each itemChecked As Object In CheckedListBox1.CheckedItems
CheckedListBox1.Items.Remove(itemChecked)
Next
I have been reading on this for hours today to find out why the first code block works, but the second does not.What I've learned is the "For Each" statement implements the IEnumerable interface. I have seen these terms used many times and scratched my head when it didn't make scense, then just moved along, something to strain my brain about later.Today was later...So since the IEnumerable interface is used, the .GetEnumerator method of the IEnumerable interface is called upon at the beginning of the "For Each" block, this evaluates the collection or list as in: For Each item As ListViewItem In myCollection This is done at the beginning of the iteration through the myCollection, so if the myCollection is altered as in:
For Each itemChecked As Object In myCollection
CheckedListBox1.Items.Remove(itemChecked)
Next
The altering of the list returns the error:List that this enumerator is bound to has been modified. An enumerator can only be used if the list does not change.
[code].....
View 9 Replies
Jun 25, 2011
I am trying to add the file information of the contents of a folder to a collection. Although I am getting the collection to hold the correct number of items that the folder contains, all of the collection's items are the details of the last file in the folder.
I'm trying to use a loop to go through each item contained in the folder and then adding the item details to a collection with the following line
nCounter += 1
collFileDetails.Add(NameOfItem, nCounter)
Next NameOfItem
View 3 Replies
Apr 15, 2010
CAUTION: Noob using Win32 API ahead
I want to display a list of open windows on my computer in a rich text box. So, I'm trying to store the names of all windows in myString, and then set RichTextBox1.Text = myString.
Here's the code
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
[Code].....
View 15 Replies
Jun 15, 2012
I am trying to work out a way to group a collection of items like an enum so that I can access them through code else where in my program. i.e I have list of items and sub items
[Code]...
View 13 Replies
Jun 15, 2012
I am trying to work out a way to group a collection of items like an enum so that I can access them through code else where in my program.
i.e I have list of items and sub items
CODE:
I would then like to be able to access then like: G1Level1.Leve2.Leve3
Would anyone be able to advise if this is possible or achievable.
View 2 Replies
Jul 12, 2011
I've done a little bit of LINQ but I almost exclusively return some elements from a collection based on some criteria. Now I'm trying to do something similar; let's say I have 50 winForm Controls in a collection - I want to set the .Visible property = True based on the controls name.
How would I do that? Below is my failed attempt.
myControls.AsEnumerable.Select( Function (myControl as Control) ( myControl.Visible = (myControl.Name <> "Hidden")) )
It compiles and even executes but does nothing.
View 1 Replies
Nov 10, 2009
I have a ComboBox control with some items added to the items collection in design mode. What I want is when an item is picked from the ComboBox a different value is actually used in the code, instead of what is displayed. I am aware of the DisplayMember & ValueMember properties, but I'm not sure if that is what I need to use. All the examples I found were for bound data.
View 3 Replies
Jun 16, 2009
I have a problem getting the collection of items in the ItemMouseHover event. I want to get the collection of all the items and subitems when the Mouse Hovers in the ListView. I have the property of Full Row select in the ListView.
View 4 Replies
Jun 16, 2009
i have a problem getting the collection of items in the ItemMouseHover event. I want to get the collection of all the items and subitems when the Mouse Hovers in the ListView. I have the property of Full Row select in the ListView.
View 2 Replies
Oct 13, 2009
How to create collection class and add list of items to collection class that stores list of items?
View 3 Replies
Apr 27, 2010
I am trying to refresh my combobox when an item is selected and added the highlighted code as shown below; [code]Items collection cannot be modified when the DataSource property is set.
View 3 Replies
Sep 13, 2011
Can I safely modify -I mean: remove and re-add on a different index position- any item that I iterate over using a For Each loop in VB? We are talking about the VB Microsoft.VisualBasic.Collection class.And if yes: Is this by design, or an implementational detail, that I am building upon then?
View 3 Replies
Sep 2, 2009
I have a string array called m_DirFileList and a collection called myFileCollection. I'm trying to loop through the items in the collection and store each one in the string array. It's not working though.
[code]...
View 2 Replies
Sep 28, 2009
I have a string array called m_DirFileList and a collection called myFileCollection. I'm trying to loop through the items in the collection and store each one in the string arrayIt's not working though. This is what I'm trying to do:
Dim myFileCollection As Collection = clsFTPClientClass.GetFileList(fileFilter, True)
intItems = clsFTPClientClass.GetFileList(fileFilter, True).Count()
[code].....
View 2 Replies
Jul 14, 2011
Is it possible to use LINQ to query the items collection of a ComboBox & get the index of the item that matches what I'm looking for?
View 4 Replies
Jul 1, 2009
I often use a for/next loop to cycle through a collection to find a particular member of that collection based on some criteria. This works fine in every case except one: when I want to then erase the very member of the collection I just found. For example, if I wanted to give the heave-ho to every obect in a collection class that has a member veriable Color equal to Red:
[Code]...
The problem is once the collection class member is erased it makes to loop invalid because taking out the member reduces the total count of the collection in the middle of the loop. Eventually I get a "Index is out of range" error.This circumstance has bothered me every so often; I bet more experienced programmers have a different type of loop system that works better than this when you want to erase a collection member.
View 2 Replies
Jun 17, 2010
I have a combobobox on my form, and I use the following code to populate the data from SQL Server:
cbname.DataSource = DSAssetName.Tables(0)
cbname.DisplayMember = "IDWLNAME"
cbname.ValueMember = "FIDWID"
[code].....
View 2 Replies
Dec 30, 2010
I can't seem to find any answers that work. Here's the setup:
Info class: Public Class ProductStageInfo
[Code]...
maybe I just don't understand the whole collection/index/thing. All the examples I've found are regarding single dimension collections - 'how to find name within this collection', and the responses use strings to search through them, but somehow the Info class is being treated differently, and I'm not sure how to translate this..
View 1 Replies
Jun 1, 2011
I have a Microsoft.VisualBasic.Collection where they keys are
"123,A"
"123,B"
Is there a way to remove all keys where they begin with 123?
View 1 Replies
May 12, 2011
I would like to be able to save to a db and send task to email or as text msg for instance nevermind that.. I have two variables of type ArrayList they are "_mList1" , "_mList2" and "_mList3"
_mList1 stores the list of Telephonenumbers , _mList2 stores the list of StaffIDs and _mList3 Some concatenated string.
theses variable lists will hold some data in runtime as explained and i would like to use them to populate a DB table again mentioned
tblTask (TaskID(PK), Action, StaffID(FK), AssignedBy, TelephoneContacted, NotesCotent)
tblStaff (StaffID(PK), FirstName, Surname, Telephone, Address etc..)
[Code]....
View 1 Replies
Jan 16, 2010
I'm trying to create an inherited version of the ListView control that (among other things) should have a different background image if the listview is empty to if it has items.Obviously you can easily enough test the count of the collection, but I need to be able to react to the event, however there doesn't appear to be any event related to adding/removing items.
View 3 Replies
Feb 13, 2010
I have two tables "Person" and "Alias" in a one to many relationship. I have a DGV for "Person" and want to use a combobox for the Aliases. I also have a textbox and a button for the user to type the alias name and click the button to add the alias name to the combobox and update the dataset. I keep getting the "Items collection cannot be modified when the DataSource property is set." Error. But if i use a DGV instead of a combobox for aliases, I have no errors and everything works fine. If I remove the datasource property for the combobox it will not get populated with the data already entered, so how, or can I, set it up where the combobox gets populated when the form loads and able to add items to the combobox????
View 1 Replies
Aug 10, 2011
I am trying to create a basic quoting tool but got stuck on how to clear and change the item collection from within a combobox for a datagrid.What we have is a list of 4 columns like a. Device b.TypeofService c.State d.Price Inside a sql database. Data is also structure like above as well.
I have a datagridview where the user will populate a,b,c and the price will be display and a total at the end. However a,b, and c aren't related in my current application. The combobox will show all possible dinstinct values for each column.
This works fine but I want to refine the application to only show the values of b. which are in the database after the user select the value for a. I have tried searching on how to do this as I assume to the Contry/State/City situation but could not find anything for a datagridview control in VB.NET.
Can anyone point me in the right direction? If I cannot do this dynamically from within a datagridview I was thinking of maybe creating three combo box outside and having it populating the datagridview afterwards but it wouldn't be as nice.
View 3 Replies