473,545 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

'findstring' in listbox

Hello.
Can someone tell me what I may be doing wrong here?

I'm using the code (lboxRP is a listbox):

Dim newRPindex As Integer
newRPindex = Me.lboxRP.FindS tring(RP)
Me.lboxRP.SetSe lected(newRPind ex, True)

When the last line executes, I get an error message:

An unhandled exception of type 'System.Argumen tOutOfRangeExce ption' occurred
in system.windows. forms.dll

Additional information: Specified argument was out of the range of valid
values.

If I 'mouse-over' my code, the value RP is the string it should be, and it
does exist as an item in the listbox...

Help!!

TIA
Amber
Jul 21 '05 #1
17 3092
Put a break on the line:
Me.lboxRP.SetSe lected(newRPind ex, True)
Now what's the value of newRPindex when you mouseover it?

It will need to be 0 or greater to use the SetSelected method.

"amber" wrote:
Hello.
Can someone tell me what I may be doing wrong here?

I'm using the code (lboxRP is a listbox):

Dim newRPindex As Integer
newRPindex = Me.lboxRP.FindS tring(RP)
Me.lboxRP.SetSe lected(newRPind ex, True)

When the last line executes, I get an error message:

An unhandled exception of type 'System.Argumen tOutOfRangeExce ption' occurred
in system.windows. forms.dll

Additional information: Specified argument was out of the range of valid
values.

If I 'mouse-over' my code, the value RP is the string it should be, and it
does exist as an item in the listbox...

Help!!

TIA
Amber

Jul 21 '05 #2
The value is -1.
That's the problem - I'm trying to set it to equal the index that the
findstring returns.
TIA
Amber

Jul 21 '05 #3
Try setting the initial search location to -1,
newRPindex = Me.lboxRP.FindS tring(RP, -1)

You've checked that there's RP is not prefixed or suffixed with spaces
(chr$(32))?

"amber" wrote:
The value is -1.
That's the problem - I'm trying to set it to equal the index that the
findstring returns.
TIA
Amber

Jul 21 '05 #4
Also, you can use
newRPindex = Me.lboxRP.FindS tringExact(RP)
"amber" wrote:
The value is -1.
That's the problem - I'm trying to set it to equal the index that the
findstring returns.
TIA
Amber

Jul 21 '05 #5
Okay, I tried that - still doesn't work.
It seems so straightforward ...I'm confused as to why it won't work.

when I use the line :

dim newRPindex as integer = me.lboxRP.FindS tring(RP, -1)

the value 'RP' comes from the listbox...
All I'm trying to accomplish is this:
I have a listbox with multiple items. When the user makes changes to the
form, and saves, it updates everything, and repopulates the listbox.
I'm trying to save the current item that is selected, then reselect it after
the update.

Any other suggestions??
TIA.
Amber
"Mike S." wrote:
Also, you can use
newRPindex = Me.lboxRP.FindS tringExact(RP)
"amber" wrote:
The value is -1.
That's the problem - I'm trying to set it to equal the index that the
findstring returns.
TIA
Amber

Jul 22 '05 #6
You've narrowed the problem down to the FindString function not finding the
string representation of the object RP. How are you dimensioning and
assigning RP?

Try this to see if you can return a value:
dim newRPindex as integer = me.lboxRP.FindS tring("Your List Item Text")

"amber" wrote:
Okay, I tried that - still doesn't work.
It seems so straightforward ...I'm confused as to why it won't work.

when I use the line :

dim newRPindex as integer = me.lboxRP.FindS tring(RP, -1)

the value 'RP' comes from the listbox...
All I'm trying to accomplish is this:
I have a listbox with multiple items. When the user makes changes to the
form, and saves, it updates everything, and repopulates the listbox.
I'm trying to save the current item that is selected, then reselect it after
the update.

Any other suggestions??
TIA.
Amber
"Mike S." wrote:
Also, you can use
newRPindex = Me.lboxRP.FindS tringExact(RP)
"amber" wrote:
The value is -1.
That's the problem - I'm trying to set it to equal the index that the
findstring returns.
TIA
Amber

Jul 22 '05 #7
Thanks for all you help!
It's still not working for me.
I'll post my complete code.

The sub that uses findString is:

Private Sub refreshRoadPerm it(Optional ByVal deleteRecord As Boolean =
False, Optional ByVal RP As String = "")
If deleteRecord = True Then
"Mike S." wrote:
You've narrowed the problem down to the FindString function not finding the
string representation of the object RP. How are you dimensioning and
assigning RP?

Try this to see if you can return a value:
dim newRPindex as integer = me.lboxRP.FindS tring("Your List Item Text")

"amber" wrote:
Okay, I tried that - still doesn't work.
It seems so straightforward ...I'm confused as to why it won't work.

when I use the line :

dim newRPindex as integer = me.lboxRP.FindS tring(RP, -1)

the value 'RP' comes from the listbox...
All I'm trying to accomplish is this:
I have a listbox with multiple items. When the user makes changes to the
form, and saves, it updates everything, and repopulates the listbox.
I'm trying to save the current item that is selected, then reselect it after
the update.

Any other suggestions??
TIA.
Amber
"Mike S." wrote:
Also, you can use
newRPindex = Me.lboxRP.FindS tringExact(RP)
"amber" wrote:

> The value is -1.
> That's the problem - I'm trying to set it to equal the index that the
> findstring returns.
> TIA
> Amber
>

Jul 22 '05 #8
Close... but not the exact code I was looking for.

How do you pass the RP string to the refreshRoadPerm it function?

Post the calling line if you can

"amber" wrote:
Thanks for all you help!
It's still not working for me.
I'll post my complete code.

The sub that uses findString is:

Private Sub refreshRoadPerm it(Optional ByVal deleteRecord As Boolean =
False, Optional ByVal RP As String = "")
If deleteRecord = True Then


Jul 22 '05 #9
I'm not sure what happened there...I was typing away, looked up, and it was
gone. Hopefully I didn't accidentally send an incomplete message...

Okay, here is the code in my sub that uses the FindString method:

Private Sub refreshRoadPerm it(Optional ByVal deleteRecord as Boolean =
False, Optional ByVal RP As String = "")

RoadPermitIsDir ty = False
If deleteRecord = True Then
'refresh and select 1st Road Permit
getRoadPermits( )
Else
getRoadPermits( )
'reselect previously selected Road Permit
Dim newRPindex as Integer
newRpindex = me.lboxRP.FindS tring(RP, -1)
Me.lboxRP.SetSe lected(newRPind ex, True)
End If
End Sub

I assign RP it's value in another sub

public Sub UpdateRoadPermi t()
dim drv as DataRowView = Me.lboxRP.Selec tedItem
dim cRP as New RoadPermit
...lots of other code
cRP.RoadPermitN ame = Me.txtRP.Text
refreshRoadPerm it(False,cRP.Ro adPermitName)
End Sub

Now I can see that RoadPermitName is correct - and there doesn't appear to
be any spaces where there shouldn't be.
I'm baffled.

After reading this lengthy post...any new suggestions?
:)
TIA
Amber

Jul 22 '05 #10

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

Similar topics

0
1065
by: Rene Aguirre | last post by:
Hello everybody, I had this problem using the FindString funcion of a wxChoice object on wxPython: * I have Windows 98 * I read a text file edited on a Japanese computer, but only uses 'english' characters. * From the file I loaded some strings in some wxChoice object. * Later when I wanted to find an string using 'FindString' I never...
1
2761
by: Marcin Floryan | last post by:
Hello! I have recently come across two very nice methods in ListBox control: ..FindString and .FindStringExact it is very usefull for me, and I would like to use it in some other situations. Where could I find an implementation of thiese methods or other similar solutions. I would like to use such methods without ListBox - only with a...
2
2060
by: Jorge | last post by:
Hello I have a little problem i have a checkedlistbox with several repeated items. The code below only selects the first ocurrence While reader.Read For i = 0 To Me.CheckedListBox1.Items.Count - 1 Me.CheckedListBox1.SetItemChecked (Me.CheckedListBox1.FindString(reader.GetString(0)), True)
17
342
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP) Me.lboxRP.SetSelected(newRPindex, True) When the last line executes, I get an error message:
0
7467
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...
0
7401
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...
0
7807
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...
1
7419
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
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...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1879
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
1
1014
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.