.net - WPF: "Items Collection Must Be Empty Before Using ItemsSource"
Mar 25, 2009
I'm trying to get images to display in a WPF ListView styled like a WrapPanel as described in this old ATC Avalon Team article: How to Create a Custom View. When I try to populate the ListView with a LINQ-to-Entities queried collection of ADO.NET Entity Framework objects I get the following exception:
[Code]...
View 9 Replies
ADVERTISEMENT
Nov 18, 2011
I'm trying to create a datagrid with auto generating columns. Let's say my Collection is a property named Articles of my viewmodel of type ObservableCollection<ArticleWrapper>.
I bind now the ItemsSource to this collection:
<wpf:DataGrid ItemsSource={Binding Articles} />
The class ArticleWrapper is like this:
[c#]
public class ArticleWrapper
{
public ArticleConfigurationSet ArticleConfigurationSet { get; set; }
public string Description { get; set; }
[Code]....
But now my problem: I want to bind the displayed data to my ArticleConfigurationSet property. But I cannot change my ItemsSource Binding, because the SelectedItem property of the datagrid must be of ArticleWrapper (for command handling).
The datagrid should also look like this:
View 3 Replies
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
Apr 11, 2010
How can I empty a collection in .NET? Let me specify that I don't want to destroy the collection , I just don't want it to have the objects it had before (so I can refill it from scratch) .
View 3 Replies
Aug 19, 2009
How can i check if a string collection is empty? I tried
VB.NET
My.Settings.IPBank.Count = 0
But it said
Quote:
Object reference not set to an instance of an object.
View 6 Replies
Dec 21, 2010
I have a list of user names (we'll call 'original list') one object is returning. I have a list of user names (we'll call 'filtration list') another object is returning. I am testing a method that returns all of the items from the original list not in the filtration list. Ideally what I want is something like:
Assert.That(returnedList, Has.No.Members.In(filtrationList))
So far the only thing I can do is iterate over the filtrationList and do
Assert.That(returnedList, Has.None.EqualTo(filteredUser))
View 1 Replies
Mar 6, 2009
the vars outside the procedure
Dim rentalRecords As New ArrayList() ' The arraylist containing the records
Dim carRecords As New ArrayList()
Dim currentRecordIndex As Integer ' The index of the current record
[code]....
View 1 Replies
Jul 1, 2009
treeView control which has been plaguing me for the last few days.
I'm not exactly sure what is causing this problem to arise, so I will just explain what my program is trying to do.
I am building an application which will have plugin support. I have created a Plugin interface, which is implemented by each plugin, as well as a host interface, which is implemented only by the host application.
Each plugin has an Action subroutine, and when finished, it is supposed to call the ExecutionComplete subroutine in the host interface.
Now, onto the problem. I have a treeView on the host form, which has several nodes in it. If I create a button on the form which displays a message box with treeView.nodes.count, it shows up fine, and everything works as expected. If I attempt to display the same messagebox from the ExecutionComplete subroutine, it also gives the correct number of nodes.
This is where things get a little weird. I have implemented a save feature into my program, so you can save and load data. For some weird reason, if you have loaded the data from a file, rather than adding each node manually, it now returns an empty node collection ONLY if I try to access it from ExecutionComplete. If I try to access the nodes from a button, it still returns the correct values!
What could it possibly be about the ExecutionComplete subroutine that makes it return a value any different than what is returned when the exact same code is placed in a button click event? And why does it only happen when I've loaded the data from a file? I just don't understand how loading it from a file is any different than them adding the nodes manually. The nodes are definitely being added, as I can see them, and the button click event can also see them. Also, ExecutionComplete is obviously able to read the contents of the treeView, because it works just fine if the user has set up the treeView manually.
View 9 Replies
Jan 14, 2011
I am trying to set the itemssource for my WPF-based VB 2010 project to a datatable item. The datatable is "roster_table" and the column name I want to display the items from in the list box is "DATA_NAME". The listbox is "lstNames".
I can't find a straight answer anywhere. How do I set the itemssource for the listbox to the datatable's column, as described above?
View 1 Replies
Jun 14, 2010
UPDATE: See the bottom of this question for what I did to solve the problem.I'm trying to understand how the ItemsSource and DataContext properties work in a Silverlight Toolkit DataGrid. I'm currently working with dummy data and trying to get the data in the DataGrid to update when the value of a combo box changes.
View 2 Replies
Jun 9, 2012
I need to know if there is a way to remove any items from a listbox if they contain no text. Like if there are three items(Blah, ,Blah) listed in the listbox like so (remove the middle line that is empty so the listbox now contains two items(Blah, Blah) listed like so Or if there is a way to do this to a textbox that would work too. I'm working in VB 2010
View 3 Replies
Feb 15, 2010
why is this xml
<?xml version="1.0" encoding="utf-8"?>
<items>
<item id="77" cityID="EE12345" cityDatum="15.2.2010. 11:28:35" />
</items>
[Code]....
If you, as some can't replicate these results, here's a screenshot:
View 1 Replies
Dec 15, 2011
I've got a Program and a text file, this text file gets load into the list box but that's not the problem. The problem is that when I make the text file it makes a open line and this line gets loaded into the list box and I don't want empty items.
So here's code that I use to make text file
Public MySettingfile As String = My.Application.Info.DirectoryPath & "Process History.MemFreo" Dim myCoolWriter As New IO.StreamWriter(MySettingfile, True, System.Text.Encoding.Default)
myCoolWriter.WriteLine()
myCoolWriter.Close()
View 8 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
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
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