472,954 Members | 2,156 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,954 software developers and data experts.

ComboBox.SelectedIndex bug?


Has anyone experienced problems with
a combo box SelectIndex property?
Is there a limit to the number of Items
for a combo box?

Namely, when I set programmatically
ComboBox.SelectIndex property
with 2000 Items listed in the ComboBox,
SelectIndex property accepts assigned
value. However, when I try to use SelectIndex
property with 5000 Items populating
the ComboBox, the SelectIndex property
does not pick up the programmatically
assigned value?

This is amazingly annoying feature/bug(?).
Anyone knows any kind of a workaround/fix?

Thanks,

--
Strah @ Langan
Nov 20 '05 #1
4 2562
Cor
Hi Strahmir,

I did made this code and it did fire

I hope this helps?

Cor
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim statesTable As New DataTable
statesTable.Columns.Add(New DataColumn("Name"))
Dim dr As DataRow
For i As Integer = 0 To 4999
dr = statesTable.NewRow()
dr(0) = i
statesTable.Rows.Add(dr)
Next
ComboBox1.DataSource = statesTable.DefaultView
ComboBox1.DisplayMember = "Name"
flag = True
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
If flag = True Then
MessageBox.Show("fired")
End If
End Sub
///
Nov 20 '05 #2
Thanks Cor for your effort and help.
Something strange is happening to ComboBox
and I my question was not probably put right.

By additionally playing around with my code
I figured, that after all, it is not a number of
Items in the ComboBox, but something in
relation with ComboBox 'default' select index
if there is such thing. Here is what I mean;
I pull 5000+ Items from the database and
populate a ComboBox. I want to utilize
the ComboBox_KeyPress - see code below.

There was much more code in the ComboBox_KeyPress
event but I reduced it to what troubles me.
So what happens is that, I populate the Combobox,
and when I start using keyboard, I would like to set
SelectedIndex to a certain value.

With the code below, the behavior is really strange.
Fore example, if I start typing 3, and there is an Item
starting with 3 it will select that Item instead of
the Item with index = 3. Why is that? On the other
hand, if I start with 7, and there is no Item starting
with 7, it will select Item with index = 3 (?). Why?
And finally, Item with index = 3, starts with 1, and
if I start typing 1, it does not select Item with index =3
but rather Item with index = 4. I find this behavior
very strange. Should I not be able to set
ComboBox.SelectedIndex in the ComboBox_KeyPress
event? Any reason for that? Why my index, in the
ComboBox.SelectedIndex gets overwritten?
What am I missing?

Thanks

Private dbconn As OleDb.OleDbConnection

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.ComboBox1.DataSource = GetJobNumbers()
AddHandler ComboBox1.KeyPress, AddressOf ComboBox_KeyPress
End Sub
Private Function GetJobNumbers() As System.Collections.ArrayList
Dim al As New ArrayList()
Dim drJobNumbers As OleDb.OleDbDataReader
Try
' Get connection
Dim strConnectionString As String =
"Provider=SQLOLEDB;Driver={SQL Server}; Server=ServName;
Database=dbname;UID=username;PWD=password"
dbconn = New OleDb.OleDbConnection(strConnectionString)

Dim sGetJobNumbers As String = "SELECT * FROM PR WHERE prTask =
'' AND prStatus = 'A' ORDER BY prProject ASC"
Dim cmd As OleDb.OleDbCommand = New
OleDb.OleDbCommand(sGetJobNumbers, dbconn)
dbconn.Open()
drJobNumbers = cmd.ExecuteReader
Dim sEvalJobNumber As String
Dim iEvalJobNumber As Integer
Do While drJobNumbers.Read
sEvalJobNumber = drJobNumbers.Item(0)
If Microsoft.VisualBasic.Len(sEvalJobNumber) = 7 And _
Microsoft.VisualBasic.IsNumeric(sEvalJobNumber) Then
iEvalJobNumber = CType(sEvalJobNumber, Integer)
If iEvalJobNumber > 1000123 Then
al.Add(drJobNumbers.Item(0).ToString)
End If
End If
Loop
Catch ex As Exception
Debug.WriteLine(ex.Message)
Finally
drJobNumbers.Close()
dbconn.Close()
End Try
Return al
End Function
Private Sub ComboBox_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs)
Dim cbx As ComboBox = CType(sender, ComboBox)
cbx.SelectedIndex = 3
End Sub
--
Strah @ Langan

"Cor" <no*@non.com> wrote in message
news:O0**************@tk2msftngp13.phx.gbl...
Hi Strahmir,

I did made this code and it did fire

I hope this helps?

Cor
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim statesTable As New DataTable
statesTable.Columns.Add(New DataColumn("Name"))
Dim dr As DataRow
For i As Integer = 0 To 4999
dr = statesTable.NewRow()
dr(0) = i
statesTable.Rows.Add(dr)
Next
ComboBox1.DataSource = statesTable.DefaultView
ComboBox1.DisplayMember = "Name"
flag = True
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
If flag = True Then
MessageBox.Show("fired")
End If
End Sub
///

Nov 20 '05 #3
Cor
Hi Strahimir,

I have been busy with an other thing in the Combobox last days.

The behaviour of your code looks a little bit like this for me

http://support.microsoft.com/default...b;en-us;814346

But I have seen many strange things with the combobox, I would not seek to
deep if I was you and just try to find a workaround for the problem.

Cor
Nov 20 '05 #4

Cor,

thanks again. Just having you said "But I have seen many strange things
with the combobox", makes me feel better, knowing I am not the only one.
I am on the edge of frustration and has found some workaround, but it
should not be that difficult to deal with. Thanks,

Strah

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #5

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

Similar topics

13
by: Mr. B | last post by:
Here's the situation... You've a combobox with Items already added. Say they look like this (or even lines of text): 10-00-232 10-00-256 10-01-006 10-01-213 10-02-200
8
by: Supa Hoopsa | last post by:
I have a databound combobox within a datagrid. I have set the DisplayMember and ValueMember. BUT, how do I capture the Value (SelectedValue) when the user changes the selection?
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...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
5
by: ross kerr | last post by:
Hi All, I am extending the combobox to create a control that selects an item based on the text the user is typing into the text area of the control. I have an issue that occurs only when i...
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...
3
by: Ivan V via DotNetMonster.com | last post by:
Hi All: I would like to know if I can loop my selection in a combobox. For instance, I got 8 items in a combobox, and when I selected it using the up and down arrow, it will stop in the first...
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: Eric A. Johnson | last post by:
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...
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...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
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...
1
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.