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.This property is a
collection of placealias classes. Hopefully the rest is
self-explanatory..
I bind the control as follows:
If SelectedPlace.PlaceAliases.Count > 0 Then
SetCLBAliasDataSource()
Else
clbAliases.DataSource = Nothing
End If
Private Sub SetCLBAliasDataSource()
clbAliases.DataSource = Nothing
clbAliases.DisplayMember = "AliasName"
clbAliases.DataSource = SelectedPlace.PlaceAliases
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.EventArgs) Handles btnDeleteAlias.Click
If SelectedPlace.PlaceAliases.Count = 1 Then
MsgBox("You cannot delete the primary alias.")
Exit Sub
Else
Dim item As Object
For Each item In clbAliases.CheckedItems
'clbParents.Items.Remove(item)
SelectedPlace.PlaceAliases.Remove(item.placenameid )
Next
'this forces the control to rebind to the modified
collection
SetCLBAliasDataSource
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.ArgumentOutOfRangeException'
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 4 3766
I don't have the answer for you but I have an advice: Stay away from
databound CheckedListBoxes.. 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.com> wrote in message
news:4f**************************@posting.google.c om... 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.This property is a collection of placealias classes. Hopefully the rest is self-explanatory..
I bind the control as follows:
If SelectedPlace.PlaceAliases.Count > 0 Then SetCLBAliasDataSource() Else clbAliases.DataSource = Nothing End If
Private Sub SetCLBAliasDataSource() clbAliases.DataSource = Nothing clbAliases.DisplayMember = "AliasName" clbAliases.DataSource = SelectedPlace.PlaceAliases 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.EventArgs) Handles btnDeleteAlias.Click If SelectedPlace.PlaceAliases.Count = 1 Then MsgBox("You cannot delete the primary alias.") Exit Sub Else Dim item As Object For Each item In clbAliases.CheckedItems 'clbParents.Items.Remove(item) SelectedPlace.PlaceAliases.Remove(item.placenameid ) Next 'this forces the control to rebind to the modified collection SetCLBAliasDataSource 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.ArgumentOutOfRangeException' 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
"TJoker .NET [MVP]" <no****@nonono.no> wrote in message news:<up**************@TK2MSFTNGP10.phx.gbl>... I don't have the answer for you but I have an advice: Stay away from databound CheckedListBoxes.. 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. ma****************@hotmail.com (Matthew) wrote in message news:<4f**************************@posting.google. com>... "TJoker .NET [MVP]" <no****@nonono.no> wrote in message news:<up**************@TK2MSFTNGP10.phx.gbl>... I don't have the answer for you but I have an advice: Stay away from databound CheckedListBoxes.. 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 ma****************@hotmail.com (Matthew) wrote in message news:<4f**************************@posting.google. com>... "TJoker .NET [MVP]" <no****@nonono.no> wrote in message news:<up**************@TK2MSFTNGP10.phx.gbl>... I don't have the answer for you but I have an advice: Stay away from databound CheckedListBoxes.. 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.ArgumentOutOfRangeException'
occurred in microsoft.visualbasic.dll
Additional information: Specified argument was out of the range of
valid values. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
by: Steve Teeples |
last post by:
Can someone show me an example of how to place a "CheckedListBox" property
within a PropertyGrid?
--
-----------
Thanks,
Steve
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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...
| |