Adding an item to a Checked List Box

VB.NET

    Next

  • 1. How to get an active window's size (width and height)
    Hi, I need to show an active window's (form) size(width and height in pixels) in message box, however there are some low-level api calls in user32.dll but i don't know which function returns the correct information. What's the correct user32.dll api function (GetWindowPlacement?) and syntax? I supposed there would be a class in .NET 2.0 instead of struggling Windows API. Thanks.
  • 2. RichTextBox - the correct choice and how to loop
    Hello, I'm working on a pretty simple web app in which the user will be pasting in a list of values (letters and number - like "1V456") most likely from an Excel worksheet. I then want the application to check this list against tables in a sql server database for different things (like - does it exist in database, etc.) My co-worker thinks that a richtextbox is the best control to use for this. I'm new to VB.Net so I'm not real familiar with this control. Is it the right way to go? I've been doing a little research on the web and don't see it used too much for this situation. I have been playing with it a bit and have gotten results to point to a table, but it is adding in strange characters and blank entires. Here is the code: <code> For Each str As String In RichTextBox1.Lines InsertSQL = "Insert into Test_test values ('" & str & " ')" dr1 = SqlHelper.ExecuteReader(CONNSTRING, CommandType.Text, InsertSQL) Next </code> Is a "For each" statement the way to go? Thanks in advance for your time! JCC

Adding an item to a Checked List Box

Postby Simon Jefferies » Fri, 16 Apr 2004 21:04:58 GMT

Hello,

I am trying to add an item to a checked list box, like:

clbList.Items.add("Hello",true)

I get an error back:

Run-time exception thrown: System.ArgumentOutOfRangeException - Specified 
argument was out of the range of valid values. Parameter name: '-1' is not a 
valid value for index.

This doesn't make a lot of sense? Any ideas why this happens?

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto: XXXX@XXXXX.COM 
- 



Re: Adding an item to a Checked List Box

Postby hirf-spam-me-here » Fri, 16 Apr 2004 22:04:39 GMT

Simon,

* "Simon Jefferies" < XXXX@XXXXX.COM > scripsit:

I am not able to repro that.  Are you sure this line throws the
exception?  Which version of .NET do you use?

-- 
Herfried K. Wagner [MVP]
<URL: http://www.**--****.com/ ;

Re: Adding an item to a Checked List Box

Postby Armin Zingler » Fri, 16 Apr 2004 22:09:42 GMT

"Simon Jefferies" < XXXX@XXXXX.COM > schrieb

Can't repro the prob with VB 2003. Please show me the real line of code (the
above one isn't).


-- 
Armin

How to quote and why:
 http://www.**--****.com/ 
 http://www.**--****.com/ 


Re: Adding an item to a Checked List Box

Postby Simon Jefferies » Fri, 16 Apr 2004 22:12:43 GMT

Yes, the line goes green and breaks on it.

I am using .NET 2003.

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto: XXXX@XXXXX.COM 
-







Re: Adding an item to a Checked List Box

Postby Simon Jefferies » Fri, 16 Apr 2004 22:17:04 GMT

I'm running VB .NET 2003 too.

I'm trying with the line quoted just to get it to add something basic.

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto: XXXX@XXXXX.COM 
-







Re: Adding an item to a Checked List Box

Postby Armin Zingler » Fri, 16 Apr 2004 22:28:58 GMT

"Simon Jefferies" < XXXX@XXXXX.COM > schrieb

But "add" and "true" usually start with capital letters.

Can you post the callstack from your function call down to the function
throwing the exception?


-- 
Armin


Re: Adding an item to a Checked List Box

Postby Simon Jefferies » Fri, 16 Apr 2004 22:34:41 GMT

ere's the callstack, the first line looks interesting...

system.windows.forms.dll!System.Windows.Forms.CheckedListBox.SetItemCheckState(int
index = -1, System.Windows.Forms.CheckState value = Checked) + 0xbc bytes
system.windows.forms.dll!System.Windows.Forms.CheckedListBox.ObjectCollection.Add(System.Object
item = "Hello", System.Windows.Forms.CheckState check = Checked) + 0xa3
bytes
system.windows.forms.dll!System.Windows.Forms.CheckedListBox.ObjectCollection.Add(System.Object
item = "Hello", bool isChecked = true) + 0x38 bytes
hfsoundeditorplugin.dll!HfSoundEditorPlugin.frmSoundEditorView.DisplaySoundBankProperties()
Line 707 + 0xa bytes Basic
hfsoundeditorplugin.dll!HfSoundEditorPlugin.frmSoundEditorView.tvwMain_AfterSelect(Object
sender = {System.Windows.Forms.TreeView},
System.Windows.Forms.TreeViewEventArgs e =
{System.Windows.Forms.TreeViewEventArgs}) Line 622 + 0xa bytes Basic
system.windows.forms.dll!System.Windows.Forms.TreeView.OnAfterSelect(System.Windows.Forms.TreeViewEventArgs
e = {System.Windows.Forms.TreeViewEventArgs}) + 0x23 bytes
system.windows.forms.dll!System.Windows.Forms.TreeView.TvnSelected(System.Windows.Forms.NativeMethods.NMTREEVIEW*
nmtv = 1237196) + 0x9c bytes
system.windows.forms.dll!System.Windows.Forms.TreeView.WmNotify(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x137 bytes
system.windows.forms.dll!System.Windows.Forms.TreeView.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x8c bytes
system.windows.forms.dll!ControlNativeWindow.OnMessage(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x19 bytes
system.windows.forms.dll!ControlNativeWindow.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0xda bytes
system.windows.forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(int
hWnd = 24578450, int msg = 8270, int wparam = 24578450, int lparam =
1237196) + 0x39 bytes
user32.dll!77d8857a()
user32.dll!77d8867b()
user32.dll!77d89363()
user32.dll!77d893cb()
system.windows.forms.dll!System.Windows.Forms.Control.SendMessage(int msg
= 8270, int wparam = 24578450, int lparam = 1237196) + 0x40 bytes
system.windows.forms.dll!System.Windows.Forms.Control.ReflectMessageInternal(int
hWnd = 24578450, System.Windows.Forms.Message m =
{System.Windows.Forms.Message}) + 0x78 bytes
system.windows.forms.dll!System.Windows.Forms.Control.WmNotify(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x35 bytes
system.windows.forms.dll!System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x662 bytes
system.windows.forms.dll!System.Windows.Forms.GroupBox.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x6c bytes
system.windows.forms.dll!ControlNativeWindow.OnMessage(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0x19 bytes
system.windows.forms.dll!ControlNativeWindow.WndProc(System.Windows.Forms.Message
m = {System.Windows.Forms.Message}) + 0xda bytes
system.windows.forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(int
hWnd = 21432856, int msg = 78, int wparam = 24578450, int lparam = 1237196)
+ 0x39 bytes
user32.dll!77d8857a()
user32.dll!77d8867b()
user32.dll!77d89363()
user32.dll!77d893cb()
comctl32.dll!4d6daf3c()
comctl32.dll!4d6f6cb7()
comctl32.dll!4d6f8fe2()

Re: Adding an item to a Checked List Box

Postby Armin Zingler » Fri, 16 Apr 2004 22:54:45 GMT

"Simon Jefferies" < XXXX@XXXXX.COM > schrieb
system.windows.forms.dll!System.Windows.Forms.CheckedListBox.SetItemCheckSta
te(int
system.windows.forms.dll!System.Windows.Forms.CheckedListBox.ObjectCollectio
n.Add(System.Object
system.windows.forms.dll!System.Windows.Forms.CheckedListBox.ObjectCollectio
n.Add(System.Object

Yes, looks interesting. Tried to repro it again and to find the reason (IL
code) but I failed, sorry. Maybe Herfried will find out more.


-- 
Armin


Re: Adding an item to a Checked List Box

Postby hirf-spam-me-here » Fri, 16 Apr 2004 23:14:13 GMT

* "Simon Jefferies" < XXXX@XXXXX.COM > scripsit:

Enclose the line in a 'Try...Catch':

\\\
Try
    Me.CheckedListBox...
Catch
End Try
///

Is the exception still thrown?  If yes, it's not caused by the line!

-- 
Herfried K. Wagner [MVP]
<URL: http://www.**--****.com/ ;

Re: Adding an item to a Checked List Box

Postby hirf-spam-me-here » Fri, 16 Apr 2004 23:22:55 GMT

* "Armin Zingler" < XXXX@XXXXX.COM > scripsit:

I am not able to repro it on VB.NET 2002 and VB.NET 2003.  Mhm...

-- 
Herfried K. Wagner [MVP]
<URL: http://www.**--****.com/ ;

Re: Adding an item to a Checked List Box

Postby Simon Jefferies » Fri, 16 Apr 2004 23:25:30 GMT

I've changed my code to:

clbWaves.BeginUpdate()
clbWaves.Items.Clear()
Try
        clbWaves.Items.Add("Hello", True)
Catch ex As Exception
End Try

clbWaves.EndUpdate()

The Catch statement is called with the Out of range exception.

Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto: XXXX@XXXXX.COM 
www.headfirst.co.uk www.callofcthulhu.com
-







Re: Adding an item to a Checked List Box

Postby hirf-spam-me-here » Fri, 16 Apr 2004 23:44:36 GMT

Simon,

* "Simon Jefferies" < XXXX@XXXXX.COM > scripsit:

Does the exception occur if you skip the 'Clear', 'BeginUpdate', and
'EndUpdate'?  Are you sure you are performing the operation in the main
GUI thread?

-- 
Herfried K. Wagner [MVP]
<URL: http://www.**--****.com/ ;

Re: Adding an item to a Checked List Box

Postby Simon Jefferies » Fri, 16 Apr 2004 23:57:44 GMT

I don't get an exception when I comment out the BeginUpdate, Clear and 
EndUpdate.

I put back in the Clear() and its still working, so it means BeginUpdate() 
or EndUpdate() or both causes this problem?

Yes, I am performing this in the main application thread.

Why would this happen?

-- 
Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto: XXXX@XXXXX.COM 
www.headfirst.co.uk www.callofcthulhu.com
-







Re: Adding an item to a Checked List Box

Postby hirf-spam-me-here » Sat, 17 Apr 2004 05:29:54 GMT

* "Simon Jefferies" < XXXX@XXXXX.COM > scripsit:

I currently only have access to VB.NET 2002, there I am not able to
repro the "bug".

-- 
Herfried K. Wagner [MVP]
<URL: http://www.**--****.com/ ;

Re: Adding an item to a Checked List Box

Postby johnei » Sat, 17 Apr 2004 07:31:03 GMT

Hi, Simon

I can't get it to repro here either.

What happens when you start a new project, add a checked list box & a 
button, and put your code in the button's click event?  If that works, 
there is probably something wrong in your form or project files.  Have you 
edited the code in the Windows Form Designer generated code section? That 
could be the culpret.  If the simple project fails, please zip up the 
simple project and attach it to a post.  That will give us something real 
to play with.

Hope this helps,

John Eikanger
Microsoft Developer Support

This posting is provided S ISwith no warranties, and confers no rights.
--------------------
| From: "Simon Jefferies"<< XXXX@XXXXX.COM >>
| Subject: Re: Adding an item to a Checked List Box
| Date: Thu, 15 Apr 2004 15:57:44 +0100
| X-Tomcat-NG: microsoft.public.dotnet.languages.vb
| 
| I don't get an exception when I comment out the BeginUpdate, Clear and 
| EndUpdate.
| 
| I put back in the Clear() and its still working, so it means 
BeginUpdate() 
| or EndUpdate() or both causes this problem?
| 
| Yes, I am performing this in the main application thread.
| 
| Why would this happen?
| 
| -- 
| Regards
| Simon Jefferies
| Tools Programmer, Headfirst Productions
| mailto: XXXX@XXXXX.COM 
| www.headfirst.co.uk www.callofcthulhu.com
| -




|>> Simon,
|>>
|>> * "Simon Jefferies"<< XXXX@XXXXX.COM >> scripsit:
|>>> clbWaves.BeginUpdate()
|>>> clbWaves.Items.Clear()
|>>> Try
|>>>         clbWaves.Items.Add("Hello", True)
|>>> Catch ex As Exception
|>>> End Try
|>>>
|>>> clbWaves.EndUpdate()
|>>>
|>>> The Catch statement is called with the Out of range exception.
|>>
|>> Does the exception occur if you skip the 'Clear', 'BeginUpdate', and
|>> 'EndUpdate'?  Are you sure you are performing the operation in the main
|>> GUI thread?
|>>
|>> -- 
|>> Herfried K. Wagner [MVP]
|>>< 
| 
| 
| 


Similar Threads:

1.adding a check box list item using js

I tried to add in the innerHTML but it gives unknown runtime error

var parentEl=document.getElementById("cbListClassSug");

var id="cbListClassSug_"+idCnt;
var nam="cbListClassSug$"+idCnt;
parentEl.innerHTML+="<tr><td>";
parentEl.innerHTML+="<input id=\""+id+"\"";
parentEl.innerHTML+=" type=\"checkbox\"";
parentEl.innerHTML+=" name=\""+id+"\"";
parentEl.innerHTML+="
value=\""+tree1.childNodes(1).text+"_"+tree1.childNodes(2).text+"_"+tree1.childNodes(0).text+"\"";
parentEl.innerHTML+="<label for=\""+id+"\"> In Taxonomy
"+tree1.childNodes(0).text+"</label>";
                    parentEl.innerHTML+="</td></tr>";
                    idCnt++;

2.Adding list items to a DHTML List box

I am trying to dynamically add elements to a list box on a DHTML page.  I
can get the listbox object, and set the InnerHTML property for it, but I
don't get the list items even though a print of the innerHTML shows the
correct code.  I am trying to do this in the DHTMLPage_Load() event handler.
I have also noticed that I have to precede the HTML I want with an empty
tag.  I.E. if I want to add <Option Value=First>First Choice</Option>, I
have to put in <   ><Option Value=First>First Choice</Option> to have the
innerHTML show <Option Value=First>First Choice</Option>.  Can anyone tell
me what I am doing wrong here?

TIA
Ron Lounsbury


3.Accessing List Items that were added to a list box via JavaScript

Need some help guys:


I have two list boxes that I am moving LI's back and forth.  I
initially fill listboxA with a datareader.   I move any/all/some/etc
items from listboxA to listboxB.  I then cannot loop through items in
listboxB on the server.  It acts as if the items were never really
added even though I can access them through JavaScript.

Both the listboxes are server controls.  I am not reinitializing the
listboxes when trying to loop through.

Is there a way via Javascript to make the server think the li's have
been moved.


One other side note.  Serverside the count on listboxA never changes
even if I move all items to listboxB.


If there is no way to do it, can someone give a good thorough
explanation of Why not!!!


Thanks
Scott

4.check list boxes: how to assign information to items

I want a checked list box with lets say 10 items.  Each item should
have login and password information.  I want to be able to check ONLY
one item and press OK.  After pressing OK, it should populate a web
browser proxy window.

Any ideas?

Thanks :)

5.Combo Box "Not In List" VBA code to Add item to table

I have a drop down combo box that gives the user to enter an item not in 
the list by adding it to the list.  The list is a table.
It works fine on Access2003 but fails on Access2002/XP.  ON XP, it seems 
to work, shows the message that the entry has been added, then I get an 
Access error saying the item is not in the list.

Here is my code:

Private Sub Combo10_NotInList(NewData As String, Response As Integer)
intAnswer = MsgBox("The Outside Referral " & Chr(34) & NewData & _
     Chr(34) & " is not currently listed." & vbCrLf & _
     "Would you like to add it to the list now?" _
     , vbQuestion + vbYesNo, "")

If intAnswer = vbYes Then
     strSQL = "INSERT INTO tbl_Outside_Referrals " & _
              "VALUES ('999','" & NewData & "','');"
     DoCmd.SetWarnings False
     DoCmd.RunSQL strSQL
     DoCmd.SetWarnings True
     MsgBox "Addition completed." _
         , vbInformation, ""
     Response = acDataErrAdded
Else
     MsgBox "Please choose an Outside Referral from the list." _
         , vbInformation, ""
     Response = acDataErrContinue
End If
End Sub


Suggestions??

Bob

6. Add items to a list box using script in HTA

7. Check Box List Selected Items

8. checked list box item name



Return to VB.NET

 

Who is online

Users browsing this forum: No registered users and 60 guest