473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Unexplainable VB.NET Error (Can't Modify Items Collection)

I am running into a strange error when I try debugging my current
application. A form loads up with a dynamically-populated textbox full
of software titles. Upon selection of a software title and pressing 'GO'
a checkboxlist is displayed with the users who use the current software.
The checkboxlist is bound to a dataset named "DataTable" and has the
DisplayMember set to "Employee" and the DataValue set to "ID", like the
following:

----
Dim strSoftwareTitle As String = comboSoftwareTitles.Text()

Dim objConn As New OleDb.OleDbConnection
objConn.ConnectionString =
System.Configuration.ConfigurationSettings.AppSett ings("strConnection")

Dim strSQL As String = "SELECT ID, EmployeeName FROM tblSoftware WHERE "
& _
"(SoftwareTitle = '" & strSoftwareTitle & "') AND " & _
"(EmployeeName Is Not Null) ORDER BY EmployeeName ASC;"

Dim ds As New DataSet
Dim objCommand As New OleDb.OleDbCommand(strSQL, objConn)
Dim myCommand As New OleDb.OleDbDataAdapter(strSQL, objConn)

myCommand.Fill(ds, "DataTable")

Me.clBox.DataSource = ds.Tables("DataTable")
Me.clBox.MultiColumn = False
Me.clBox.DisplayMember = "EmployeeName"
Me.clBox.ValueMember = "ID"
----

When I run the application the first software title in the list happens
to be "Adobe Acrobat 6.01 Professional." When I hit 'go' I get the error
below:

----
Additional information: Cannot modify the Items collection
when the DataSource property is set.
----

The line that is highlighted in debug mode is the following:

----
Me.clBox.ValueMember = "ID"
----

If I quit and run the program again and scroll down and select "Visual
NET 2003 Enterprise" and press 'GO', the checkboxlist displays
flawlessly. What could cause my application to error upon selection of
the first selection, but not another one in the list. In the subroutine
that errors I am not modifying the Items collection. If this isn't clear
enough I can provide more information.

Any suggestions?

- Will

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #1
3 5007
Here is the exception Text:
************** Exception Text **************
System.ArgumentException: Cannot modify the Items collection when the
DataSource property is set.
at System.Windows.Forms.ListBox.CheckNoDataSource()
at System.Windows.Forms.ListBox.Sort()
at System.Windows.Forms.ListBox.EndUpdate()
at System.Windows.Forms.ListBox.SetItemsCore(IList value)
at System.Windows.Forms.ListControl.DataManager_ItemC hanged(Object
sender, ItemChangedEventArgs e)
at System.Windows.Forms.ListControl.SetDataConnection (Object
newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
at System.Windows.Forms.ListControl.set_ValueMember(S tring value)
at System.Windows.Forms.CheckedListBox.set_ValueMembe r(String value)
at SoftwareLicenseProject.Form1.btnSoftwareSearch_Cli ck(Object sender,
EventArgs e) in
C:\Inetpub\wwwroot\SoftwareLicenseProject\Software LicenseProject.vb:line
1108
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #2
I fixed it but I can't explain it.

All I had to do was change the order of the following:

Me.clBox.DataSource = ds.Tables("DataTable")
Me.clBox.MultiColumn = False
Me.clBox.DisplayMember = "EmployeeName"
Me.clBox.ValueMember = "ID"

To the following:

Me.clBox.ValueMember = "ID"
Me.clBox.DisplayMember = "EmployeeName"
Me.clBox.DataSource = ds.Tables("DataTable")
Me.clBox.MultiColumn = False

Any possible explanations of why or how this works? Some buggy aspect of
the .NET framework is the only thing I can think of. No other reason why
it would work sometimes and not others.

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #3
Hi,

"Will Chamberlain" <wi**************@devdex.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Here is the exception Text:
************** Exception Text **************
System.ArgumentException: Cannot modify the Items collection when the
DataSource property is set.
at System.Windows.Forms.ListBox.CheckNoDataSource()
at System.Windows.Forms.ListBox.Sort()
at System.Windows.Forms.ListBox.EndUpdate()
at System.Windows.Forms.ListBox.SetItemsCore(IList value)
at System.Windows.Forms.ListControl.DataManager_ItemC hanged(Object
sender, ItemChangedEventArgs e)
at System.Windows.Forms.ListControl.SetDataConnection (Object
newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
at System.Windows.Forms.ListControl.set_ValueMember(S tring value)
at System.Windows.Forms.CheckedListBox.set_ValueMembe r(String value)
at SoftwareLicenseProject.Form1.btnSoftwareSearch_Cli ck(Object sender,
EventArgs e) in
C:\Inetpub\wwwroot\SoftwareLicenseProject\Software LicenseProject.vb:line
1108
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventAr gs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage (Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(M essage& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)
According to the callstack the problem is caused because
CheckedListBox.Sorted = True and apparently it can't be True when it is
databound.

See
http://msdn.microsoft.com/library/de...ortinglist.asp

Dim dv As DataView = ds.Tables("DataTable").DefaultView
dv.Sort = "EmployeeName"

Me.clBox.Sorted = False
Me.clBox.DataSource = dv
Me.clBox.MultiColumn = False
Me.clBox.DisplayMember = "EmployeeName"
Me.clBox.ValueMember = "ID"
HTH,
Greetings

*** Sent via Developersdex http://www.developersdex.com ***

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
2
by: Mike | last post by:
Hi! I implemeted Forms colection described in this link: http://support.microsoft.com/default.aspx?scid=kb%3Ben-us%3B815707 I need to loop through the collectionbase and based on form's tag...
2
by: kscdavefl | last post by:
When I run the following code: private void applicationPermissionGrid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { if (e.Item.ItemType ==...
4
by: Sparky Arbuckle | last post by:
I am looping through a listbox collection to build a SQL string that will be used to delete items from a database. I have tried many variances of the code below but have had no luck. The code below...
2
by: Sean Carey | last post by:
I converted a C# Upload app to VB.NET and am down to one error and was hoping someone could help me with te error. I would greatly appreciate help from anyone. Here is the error: ...
9
by: Remulac | last post by:
Hello, I'm trying to get the value out of a dropdown list box and assign it to a variable. When I click on the list box, I invoke this line of code. I get the error, "Object reference not set...
2
by: isaac2004 | last post by:
hi i am creating a basic asp site that uses cookies to manage a cart for an online store. whenever i open this page without adding anything to the cart. i get an error message. here is my code ...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
8
by: trint | last post by:
I get this error: Unable to cast object of type 'System.Data.DataRowView' to type 'System.String' on this foreach and I thought it should work: foreach (string invoice in listBox2.Items) {
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.