472,779 Members | 1,754 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,779 software developers and data experts.

combobox mdi load selectedIndex

I have seen this question raised, but I cannot find an answer.

I have an MDI app, when I load an child form with a combobox being
bound in the load event, it won't allow me to set selectedindex = -1.
If it isn't an mdi child, then there isn't a problem. I have tried
setting it to -1 two times. I have tried setting the selecteditem
property to -1 and also to nothing. None of it seems to make a
difference.

Any help will be appreciated.
Kalvin

Nov 21 '05 #1
4 2368
Hi Kalvin,

Can we see some code? I have literally hundreds of such child forms and
selectedindex = -1 (twice) works fine.

Bernie Yaeger

"Kalvin" <kt***@streck.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
I have seen this question raised, but I cannot find an answer.

I have an MDI app, when I load an child form with a combobox being
bound in the load event, it won't allow me to set selectedindex = -1.
If it isn't an mdi child, then there isn't a problem. I have tried
setting it to -1 two times. I have tried setting the selecteditem
property to -1 and also to nothing. None of it seems to make a
difference.

Any help will be appreciated.
Kalvin

Nov 21 '05 #2
When the form is not an MDI child form, this works fine and there is
not a value in the combobox. When the form is an MDI child form, and
this is in the Load event, then there will be a value in the combobox.

Thank you for looking at this.

/****** CODE STARTS HERE *******/
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim LotServer As New LotServer
Dim Lots As LotCollection

Try
Dim conn As SqlConnection = New SqlConnection({your
connection})
conn.Open()

Dim dt As New DataTable
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = {your query}
cmd.CommandType = CommandType.Text
cmd.Connection = conn

Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)

da.Fill(dt)

box1.DataSource = dt
box1.ValueMember = "ID"
box1.DisplayMember = "Name"
box1.SelectedIndex = -1
box1.SelectedIndex = -1

conn.Close()

Catch exc As Exception
MessageBox.Show(exc.Message.ToString)
End Try

End Sub

Nov 21 '05 #3
Hi Kalvin,

OK, there are two 'answers'. When I followed your code, I experienced the
same condition you describe. However, when I loaded the data through a
dataset created by the vs .net wizard, it worked fine with selectedindex
= -1 twice. Also, when I load a combobox in additem mode, using a datatable
as you created, it was also fine.

HTH,

Bernie Yaeger

"Kalvin" <kt***@streck.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
When the form is not an MDI child form, this works fine and there is
not a value in the combobox. When the form is an MDI child form, and
this is in the Load event, then there will be a value in the combobox.

Thank you for looking at this.

/****** CODE STARTS HERE *******/
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim LotServer As New LotServer
Dim Lots As LotCollection

Try
Dim conn As SqlConnection = New SqlConnection({your
connection})
conn.Open()

Dim dt As New DataTable
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = {your query}
cmd.CommandType = CommandType.Text
cmd.Connection = conn

Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)

da.Fill(dt)

box1.DataSource = dt
box1.ValueMember = "ID"
box1.DisplayMember = "Name"
box1.SelectedIndex = -1
box1.SelectedIndex = -1

conn.Close()

Catch exc As Exception
MessageBox.Show(exc.Message.ToString)
End Try

End Sub

Nov 21 '05 #4


That makes sense. I need to be able to bind it to a user defined
collection. I have six combo boxes. The first one loads when the form
opens, and then the others load depending on the user choice in the
first box. What I did was is just manually load the box. Then it isn't
bound and doesn't automatically pick the first item. I would rather be
able to bind it like the others though.

Thank you for your help and input, I really appreciate it. Sometimes
it's nice just to know I'm not the only one it doesn't work right for.

/**** CODE STARTS HERE ****/
Friend Function LoadCategories(ByRef DropDown As ComboBox) As
CategoryCollection

'Written(By) : KTuel
'Parameters: DropwDown - A combobox to be filled with the
categories
'
'Task: Load all product categories
'
'Revision(History)
'02/09/2005 - Created kTuel

Dim CategoryServer As New CategoryServer
Dim Categories As CategoryCollection

Categories = CategoryServer.LoadAllCategories()

'.NET has a bug in MDI applications that when a combo box is
bound to a source and
'the combobox is populated in the load event of a child form,
you can't set the
'selectedindex to -1. Here we are populating the combobox
without binding it
Dim Category As Category
If Categories.Count > 0 Then
DropDown.SuspendLayout()

For Each Category In DirectCast(Categories,
IDictionary).Values()
DropDown.Items.Add(Category)
Next Category
DropDown.DisplayMember = "Name"
DropDown.ValueMember = "ID"

DropDown.SelectedIndex = -1
DropDown.SelectedIndex = -1

DropDown.ResumeLayout()

End If

Return Categories

End Function

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

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

Similar topics

2
by: Fred | last post by:
Hi, I am having a problem setting a combobox value in code on form load using comboBox.SelectedValue method. The code below when debugging show the combobox equal to an undefined value. The...
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....
4
by: Strahimir Antoljak | last post by:
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...
4
by: Keith | last post by:
Hello - this started out as a minor annoyance - and now is starting to bother me more and more - I'm hoping someone can help me. I would like to have a combobox display - NOT initially be blank...
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...
5
by: James P. | last post by:
Hello, For my new Windows application, all I want is to create an initial form to demo to the user to show them how it looks like with some data on it. So I figure the fastest way is to create...
8
by: Dennis D. | last post by:
Preface: I have viewed the combobox control video at Microsoft.at the movies. I want to simulate an HTML combobox as a windows application combobox with 5 to 10 selections in each box. In the...
3
by: Magnus | last post by:
Im using a set combobox (ComboBox1) to provide a selection of records from a database table. I have a typed dataset (DataSet1) that contains the typed datatable (DataTable1) that the combobox is...
6
by: tbrown | last post by:
I have a combobox with items like this: {one,two,three}. The selected index is 0, so "one" appears in the combobox text. When the user drops down the list, and selects "two", for example, I...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
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...

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.