472,983 Members | 2,305 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

ComboBox's SelectedIndex Property problem

Hi Everyone,

I am at my wit's end here. I have a combobox (combyQueryTitle) that I
need to use in order to select a query for my database project. Therefore,
I am using the comboQueryTitle_SelectedIndexChanged handler to, when a new
selection is made, update the query and refresh the display. The only
problem is that the program seems to inexplicably start with the
..selectedindex property at -1! This makes no sense to me. Furthermore,
this is, apparently, happening *before* my form loads, as not only does the
form not appear on screen, but even when I put a breakpoint at the first
possible line within the form_load handler, it still crashes; the breakpoint
is never even reached. Is there a way to locate the point at which the
property is being changed to (or created with) the value of -1? It seems to
me that it should not happen at all.
Please respond here, if possible; if you need more info, you can reach
me via AIM at ajeric74. Thank you!

-- Eric
Nov 21 '05 #1
5 9106
Me.cmbComboBox= New System.Windows.Forms.ComboBox()
Then cmbComboBox.SelectedIndex is -1 (default value)

You get an error if you would try this:
Me.cmbComboBox= New System.Windows.Forms.ComboBox()
cmbComboBox.SelectedIndex = 0

Can't you exit event _SelectedIndexChanged when the index is invalid?

With cmbComboBox
If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
Exit Sub
End If
End With
"Eric A. Johnson" <no*****@dontlookforme.com> schreef in bericht
news:7Q******************@newssvr14.news.prodigy.c om...
Hi Everyone,

I am at my wit's end here. I have a combobox (combyQueryTitle) that I
need to use in order to select a query for my database project.
Therefore,
I am using the comboQueryTitle_SelectedIndexChanged handler to, when a new
selection is made, update the query and refresh the display. The only
problem is that the program seems to inexplicably start with the
.selectedindex property at -1! This makes no sense to me. Furthermore,
this is, apparently, happening *before* my form loads, as not only does
the
form not appear on screen, but even when I put a breakpoint at the first
possible line within the form_load handler, it still crashes; the
breakpoint
is never even reached. Is there a way to locate the point at which the
property is being changed to (or created with) the value of -1? It seems
to
me that it should not happen at all.
Please respond here, if possible; if you need more info, you can reach
me via AIM at ajeric74. Thank you!

-- Eric

Nov 21 '05 #2

"Qwert" <no**@nosp.com> wrote in message
news:Wc********************@casema.nl...
Me.cmbComboBox= New System.Windows.Forms.ComboBox()
Then cmbComboBox.SelectedIndex is -1 (default value)

You get an error if you would try this:
Me.cmbComboBox= New System.Windows.Forms.ComboBox()
cmbComboBox.SelectedIndex = 0

Can't you exit event _SelectedIndexChanged when the index is invalid?

With cmbComboBox
If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
Exit Sub
End If
End With


I would like to ask for a side question.
If that is -1 (by default), how do I set the combo text when there is no
selection? Something like web pages "(Please choose a category from
list)"...

That will help a lot. TIA.

Boo K.M.
Nov 21 '05 #3
Better form would be

If not me.cmbComboBox.selectedindex=-1 then
'do something
end if

put that inside your handler....
--
--Eric Cathell, MCSA
"Qwert" <no**@nosp.com> wrote in message
news:Wc********************@casema.nl...
Me.cmbComboBox= New System.Windows.Forms.ComboBox()
Then cmbComboBox.SelectedIndex is -1 (default value)

You get an error if you would try this:
Me.cmbComboBox= New System.Windows.Forms.ComboBox()
cmbComboBox.SelectedIndex = 0

Can't you exit event _SelectedIndexChanged when the index is invalid?

With cmbComboBox
If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
Exit Sub
End If
End With
"Eric A. Johnson" <no*****@dontlookforme.com> schreef in bericht
news:7Q******************@newssvr14.news.prodigy.c om...
Hi Everyone,

I am at my wit's end here. I have a combobox (combyQueryTitle) that I
need to use in order to select a query for my database project.
Therefore,
I am using the comboQueryTitle_SelectedIndexChanged handler to, when a
new
selection is made, update the query and refresh the display. The only
problem is that the program seems to inexplicably start with the
.selectedindex property at -1! This makes no sense to me. Furthermore,
this is, apparently, happening *before* my form loads, as not only does
the
form not appear on screen, but even when I put a breakpoint at the first
possible line within the form_load handler, it still crashes; the
breakpoint
is never even reached. Is there a way to locate the point at which the
property is being changed to (or created with) the value of -1? It seems
to
me that it should not happen at all.
Please respond here, if possible; if you need more info, you can reach
me via AIM at ajeric74. Thank you!

-- Eric


Nov 21 '05 #4
Hard code that as your first selection. Then when you bind the datasource it
should fill in under that selection.

-1 means the control is initializing or is stateless(I think I read that on
MSDN) Once the form is loaded the default index=0

combo box's can be a pain....
--
--Eric Cathell, MCSA
"Boo K.M." <bo************@bkm-researcher.com> wrote in message
news:43********@news.tm.net.my...

"Qwert" <no**@nosp.com> wrote in message
news:Wc********************@casema.nl...
Me.cmbComboBox= New System.Windows.Forms.ComboBox()
Then cmbComboBox.SelectedIndex is -1 (default value)

You get an error if you would try this:
Me.cmbComboBox= New System.Windows.Forms.ComboBox()
cmbComboBox.SelectedIndex = 0

Can't you exit event _SelectedIndexChanged when the index is invalid?

With cmbComboBox
If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
Exit Sub
End If
End With


I would like to ask for a side question.
If that is -1 (by default), how do I set the combo text when there is no
selection? Something like web pages "(Please choose a category from
list)"...

That will help a lot. TIA.

Boo K.M.

Nov 21 '05 #5
I think you actually want to use .text value. Actually you can databind the
same combobox to 2 different datasources. So if you have a table that has
the query name, query you could do something like this

cbo.datasource=table
cbo.diplaymember=column0name
cbo.databinding.add(new binding("text",table,"column0name)
cbo.databinding.add(new binding("valuemember",table,"column1name)

then you would be able to get the querystring off the .selectedvalue
property.

Play around with it some, I ALWAYS have to tinker with my comboboxes because
it always seems each situation needs a different approach. Combos are a
pain...but thats because they are very powerful.
--
--Eric Cathell, MCSA
"Eric A. Johnson" <no*****@dontlookforme.com> wrote in message
news:g%******************@newssvr14.news.prodigy.c om...
As a matter of fact, is it possible to get the text associated with an
index within the combobox without actually modifying the .selectedindex
property? It is extremely annoying, trying to change within the program
code the selected index, only to have it crash because... I don't even
know why. I can't understand why it won't allow me to change the selected
index! The tooltip in VB.NET tells me that the .selectedindex method
allows me to get or set the index that is selected. Maybe if someone can
point me to a detailed explanation of this idiotic behavior and how to
work around it? I just want the invisible combobox's index to be the same
as the visible one. My AIM name is ajeric74... SOMEBODY please come online
to help me!!!

-- Eric

"Eric A. Johnson" <no*****@dontlookforme.com> wrote in message
news:vM*****************@newssvr14.news.prodigy.co m...
Okay, I have another question: What I'm trying to do is to use an
ordinary combobox to hold the query title, and an invisible combobox to
hold the actual query. I want to make it so that the invisible combobox
will change to match the visible one, thereby allowing its .text property
to contain the proper query. Is that possible?

TIA,
Eric

"ECathell" <ec******@nospam.com> wrote in message
news:Og****************@tk2msftngp13.phx.gbl...
Better form would be

If not me.cmbComboBox.selectedindex=-1 then
'do something
end if

put that inside your handler....
--
--Eric Cathell, MCSA
"Qwert" <no**@nosp.com> wrote in message
news:Wc********************@casema.nl...
Me.cmbComboBox= New System.Windows.Forms.ComboBox()
Then cmbComboBox.SelectedIndex is -1 (default value)

You get an error if you would try this:
Me.cmbComboBox= New System.Windows.Forms.ComboBox()
cmbComboBox.SelectedIndex = 0

Can't you exit event _SelectedIndexChanged when the index is invalid?

With cmbComboBox
If .SelectedIndex < 0 Or .SelectedIndex >= .Items.Count Then
Exit Sub
End If
End With
"Eric A. Johnson" <no*****@dontlookforme.com> schreef in bericht
news:7Q******************@newssvr14.news.prodigy.c om...
> Hi Everyone,
>
> I am at my wit's end here. I have a combobox (combyQueryTitle)
> that I
> need to use in order to select a query for my database project.
> Therefore,
> I am using the comboQueryTitle_SelectedIndexChanged handler to, when a
> new
> selection is made, update the query and refresh the display. The only
> problem is that the program seems to inexplicably start with the
> .selectedindex property at -1! This makes no sense to me.
> Furthermore,
> this is, apparently, happening *before* my form loads, as not only
> does the
> form not appear on screen, but even when I put a breakpoint at the
> first
> possible line within the form_load handler, it still crashes; the
> breakpoint
> is never even reached. Is there a way to locate the point at which
> the
> property is being changed to (or created with) the value of -1? It
> seems to
> me that it should not happen at all.
> Please respond here, if possible; if you need more info, you can
> reach
> me via AIM at ajeric74. Thank you!
>
> -- Eric
>
>



Nov 21 '05 #6

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

Similar topics

2
by: ross kerr | last post by:
Hi all, I have a control that extends the ComboBox object. It updates the selected item based on what the user enters in the text area. In the OnLeave event of the combobox, the selected...
3
by: Nikhil Patel | last post by:
Hi all, I am using the standard System.Windows.Forms.ComboBox controls on a form. There are 5 or 6 comboboxes and their selection depends on each other. The comboboxes behave strangely probably...
9
by: Steffen Laser | last post by:
Hi group, I have a problem that I already have posted to the german C# newsgroup. Since nobody could help me there, I'd like to try it here again: I set the selected item of a combobox like...
7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
12
by: Steve Dyte | last post by:
Hi, I've narrowed down a problem I've been having filling a combobox with the results of a query stored in a datatable. I'm setting the ValueMember and DisplayMember to the relevant column...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
5
by: Peter M. | last post by:
I'm struggling with combobox databinding with something I consider a bug... I'm binding my combobox to an array of structs. The struct exposes two public properties, ID and Name, to be used as...
0
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number...
5
by: Kevinp | last post by:
I've spent the last four hours Google searching for a way to disable items in a Combobox. I found one example in C++ which I can't get to work and another in C# that I couldn't get to work either....
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.