473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 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 2590
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
0
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...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.