473,732 Members | 2,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

CheckedListBox crashes after complex datasource is modified

Hi,

I am using a checkedlistbox on a windows form and binding it to a
collection of classes.

clbAliases is the checkedlistbox control
selectedplace is a class with property placealiases.Th is property is a
collection of placealias classes. Hopefully the rest is
self-explanatory..
I bind the control as follows:

If SelectedPlace.P laceAliases.Cou nt > 0 Then
SetCLBAliasData Source()
Else
clbAliases.Data Source = Nothing
End If
Private Sub SetCLBAliasData Source()
clbAliases.Data Source = Nothing
clbAliases.Disp layMember = "AliasName"
clbAliases.Data Source = SelectedPlace.P laceAliases
End Sub

Then when I modify the underlying collection ( eg for delete
functionality )
I have this:

Private Sub btnDeleteAlias_ Click(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles btnDeleteAlias. Click
If SelectedPlace.P laceAliases.Cou nt = 1 Then
MsgBox("You cannot delete the primary alias.")
Exit Sub
Else
Dim item As Object
For Each item In clbAliases.Chec kedItems
'clbParents.Ite ms.Remove(item)
SelectedPlace.P laceAliases.Rem ove(item.placen ameid)
Next
'this forces the control to rebind to the modified
collection
SetCLBAliasData Source
End If
End Sub
Everything works as expected, EXCEPT once the item is removed, and the
user clicks into the checkedlistbox area , specifically on any
remaining item in the box, the following error occurs:
"An unhandled exception of type 'System.Argumen tOutOfRangeExce ption'
occurred in mscorlib.dll

Additional information: Index was out of range. Must be non-negative
and less than the size of the collection."

I have experimented with refreshing the checkedlistbox, and a number
of various other attempted workarounds without success.

The error occurs whether I specify a ValueMember property or not. When
I inspect the underlying collection in the locals window, it appears
normal, as does the items collection of the control. And both contain
the expected number of items. In addition the control correctly
displays the remaining items.

I can only assume that the control is referencing a non-existent
collection member somewhere in the click event event args. Execution
breaks on the line with the class definition :

Public Class GISMain

Can anyone point out a workaround, or my mistake??

Thanks in advance for any help..

Matthew Evans
Nov 20 '05 #1
4 3795
I don't have the answer for you but I have an advice: Stay away from
databound CheckedListBoxe s.. lots of bugs there (at least on version 1.0).
If I were you I'd just populate and mark the items manually. You'll notice
that the databound Checkedlistbox does not keep its state correctly, it
likes to forget which items were selected every now and then.

--
TJoker, MCSD.NET
MVP: Paint, Notepad, Solitaire

*************** *************** **********
"Matthew" <ma************ ****@hotmail.co m> wrote in message
news:4f******** *************** ***@posting.goo gle.com...
Hi,

I am using a checkedlistbox on a windows form and binding it to a
collection of classes.

clbAliases is the checkedlistbox control
selectedplace is a class with property placealiases.Th is property is a
collection of placealias classes. Hopefully the rest is
self-explanatory..
I bind the control as follows:

If SelectedPlace.P laceAliases.Cou nt > 0 Then
SetCLBAliasData Source()
Else
clbAliases.Data Source = Nothing
End If
Private Sub SetCLBAliasData Source()
clbAliases.Data Source = Nothing
clbAliases.Disp layMember = "AliasName"
clbAliases.Data Source = SelectedPlace.P laceAliases
End Sub

Then when I modify the underlying collection ( eg for delete
functionality )
I have this:

Private Sub btnDeleteAlias_ Click(ByVal sender As System.Object, ByVal
e As System.EventArg s) Handles btnDeleteAlias. Click
If SelectedPlace.P laceAliases.Cou nt = 1 Then
MsgBox("You cannot delete the primary alias.")
Exit Sub
Else
Dim item As Object
For Each item In clbAliases.Chec kedItems
'clbParents.Ite ms.Remove(item)
SelectedPlace.P laceAliases.Rem ove(item.placen ameid)
Next
'this forces the control to rebind to the modified
collection
SetCLBAliasData Source
End If
End Sub
Everything works as expected, EXCEPT once the item is removed, and the
user clicks into the checkedlistbox area , specifically on any
remaining item in the box, the following error occurs:
"An unhandled exception of type 'System.Argumen tOutOfRangeExce ption'
occurred in mscorlib.dll

Additional information: Index was out of range. Must be non-negative
and less than the size of the collection."

I have experimented with refreshing the checkedlistbox, and a number
of various other attempted workarounds without success.

The error occurs whether I specify a ValueMember property or not. When
I inspect the underlying collection in the locals window, it appears
normal, as does the items collection of the control. And both contain
the expected number of items. In addition the control correctly
displays the remaining items.

I can only assume that the control is referencing a non-existent
collection member somewhere in the click event event args. Execution
breaks on the line with the class definition :

Public Class GISMain

Can anyone point out a workaround, or my mistake??

Thanks in advance for any help..

Matthew Evans

Nov 20 '05 #2
"TJoker .NET [MVP]" <no****@nonono. no> wrote in message news:<up******* *******@TK2MSFT NGP10.phx.gbl>. ..
I don't have the answer for you but I have an advice: Stay away from
databound CheckedListBoxe s.. lots of bugs there (at least on version 1.0).
If I were you I'd just populate and mark the items manually. You'll notice
that the databound Checkedlistbox does not keep its state correctly, it
likes to forget which items were selected every now and then.

--
TJoker, MCSD.NET
MVP: Paint, Notepad, Solitaire

*************** *************** **********

Thanks, I had the impression it was a bug. How irritating that the
complex databinding functionality is implemented with bugs. I guess I
need to give 1.1 a go.
Nov 20 '05 #3
ma************* ***@hotmail.com (Matthew) wrote in message news:<4f******* *************** ****@posting.go ogle.com>...
"TJoker .NET [MVP]" <no****@nonono. no> wrote in message news:<up******* *******@TK2MSFT NGP10.phx.gbl>. ..
I don't have the answer for you but I have an advice: Stay away from
databound CheckedListBoxe s.. lots of bugs there (at least on version 1.0).
If I were you I'd just populate and mark the items manually. You'll notice
that the databound Checkedlistbox does not keep its state correctly, it
likes to forget which items were selected every now and then.

--
TJoker, MCSD.NET
MVP: Paint, Notepad, Solitaire

*************** *************** **********

Thanks, I had the impression it was a bug. How irritating that the
complex databinding functionality is implemented with bugs. I guess I
need to give 1.1 a go.

Having spent half the day installing fwork v1.1 and visual studio
2003, I now find that the behaviour is identical. Does anyone else
have any ideas?

thanks again,

Matthew
Nov 20 '05 #4
ma************* ***@hotmail.com (Matthew) wrote in message news:<4f******* *************** ****@posting.go ogle.com>...
"TJoker .NET [MVP]" <no****@nonono. no> wrote in message news:<up******* *******@TK2MSFT NGP10.phx.gbl>. ..
I don't have the answer for you but I have an advice: Stay away from
databound CheckedListBoxe s.. lots of bugs there (at least on version 1.0).
If I were you I'd just populate and mark the items manually. You'll notice
that the databound Checkedlistbox does not keep its state correctly, it
likes to forget which items were selected every now and then.

--
TJoker, MCSD.NET
MVP: Paint, Notepad, Solitaire

*************** *************** **********

Thanks, I had the impression it was a bug. How irritating that the
complex databinding functionality is implemented with bugs. I guess I
need to give 1.1 a go.


Uh....no.. the error message was as above:

its now this:

An unhandled exception of type 'System.Argumen tOutOfRangeExce ption'
occurred in microsoft.visua lbasic.dll

Additional information: Specified argument was out of the range of
valid values.
Nov 20 '05 #5

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

Similar topics

1
4731
by: Chibi | last post by:
Hello! I'm back again with another problem. First of all, thank you to Jacob for helping me understand a bit more about NNTP commands. So now the problem: I have a collection of potentially thousands of items. I
2
1240
by: Andla Rand | last post by:
Hi, I have created a windows application in CSharp that is using a web browser control. When i did some coding to handle a chat window an exception was thrown with the following message: "COM object that has been separated from its underlying RCW can not be used" The chat browser window is constantly updating its content automatically. My question is how can i work around this problem?
0
3464
by: | last post by:
David, A partial answer to your question: The 'MultiColumn' property of a CheckedListBox does not cause it to display multiple FIELDS of an item... it causes it to display the items themselves in multiple columns. In other words, if you have 20 items in your Items
3
4703
by: Steve Cutting | last post by:
Hi all, I have a CheckedListBox on one pane of a TabControl on a form. I find that whenever the user clicks a different tab then comes back, any checks that were in the list have disappeared. After a bit of experimenting I have discovered that the problem only occurs when the CheckedListBox is using a dataset table as the source. If I manually add items to it's collection using the properties window, it works fine. If I bind it to a...
5
1408
by: Brian Mitchell | last post by:
I have no idea what I am doing wrong, but I have a CheckedListBox (Bound to an IList) on a TabControl and everytime I switch tabs I lose my checks. Is there something I'm missing? If I look at the properties of my IList class I can still see the properties have not changed (which means the items in the box should still be chekced) it's just like for some reason the ListBox doesn't keep the checks. Thanks for the help!!
1
1524
by: Capt_Ron | last post by:
Hello and thank you for taking the time to look. I Have a form that asks for options. I need the user to click any of the options listed. I'd like to use the CheckedListBox for this but I need to know how it works. I have the options in a table in a database. I would like to have the datasource of the CheckedListBox be a datareader that has 2 columns. One column is the Primary Key and the other is the text of the option.
9
8499
by: Capt_Ron | last post by:
Hello, I would like to set the value of the item in the checked list box. I have a datareader that has 2 columns. PK and TEXT I want the TEXT as the Item and the PK as the Value. I can not find anywhere that I can SET the value. But I can GET the SELECTED ITEM VALUE. Any direction would be helpfull.
0
1715
by: Terry Olsen | last post by:
Dim dirs() as string = Directory.GetDirectories(MyPath) CheckedListBox.DataSource = dirs CheckedListBox.Update For I as Integer = 0 To CheckedListBox.Items.Count - 1 CheckedListBox.SelectedIndex = I DoMySub(CheckedListBox.SelectedItem) Next The first line in the For loop (CheckedListBox.SelectedIndex = I) sometimes
6
6934
by: Steve Teeples | last post by:
Can someone show me an example of how to place a "CheckedListBox" property within a PropertyGrid? -- ----------- Thanks, Steve
0
8944
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8773
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9445
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.