Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2004

Tip: Looking for answers? Try searching our database.

Problem with ComboBox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ana Rita - 03 Sep 2004 12:17 GMT
Hello

I’m experience a problem with a combo at VB .NET.

I’m developing a window application and I’m using a combobox.

I’m populating the combo with a dataset. I set its ValueMenber and
DisplayMenber, and the selectedindex to -1. The dropdownstyle is set to
DropDown, but the problem persists whit DropDownList.
When I click in the button, it shows a message box whit theValueMenber and
DisplayMenber. Them I set again the selectindex to -1. The problem is that
the selectedIndex that the combo assume is 0, therefore it show its first
value.

This is the code that I use.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

       Dim objset As New DataSet
       Dim str1 As String
       objset = SP_Combo(strcon)
       'cb1.DataSource = objset.Tables("Destinos")
       cb1.DataSource = objset.Tables("Empregados")
       'cb1.DisplayMember = "nome"
       cb1.DisplayMember = "FirstName"
       cb1.SelectedIndex = -1
       Match = -1
       objset.Dispose()
       objset = Nothing

     
   End Sub

Public Function SP_Combo(ByVal strConn As String) As DataSet
       Dim a As String
       Dim objComm As New SqlCommand
       Dim objDataSet As New DataSet
       Dim ObjdataAd As New SqlDataAdapter
       Dim objConn As New SqlConnection(strConn)
       objConn.Open()
       With objComm
           .Connection = objConn
           .CommandType = CommandType.Text
           .CommandText = "Select EmployeeID, FirstName from Employees
order by FirstName"
           '.CommandType = CommandType.StoredProcedure
           '.CommandText = "SpNet_DestRecp"
           '.Parameters.Add(New SqlParameter("@Var_Onde",
"Combo")).Direction = ParameterDirection.Input
       End With
       ObjdataAd.SelectCommand = objComm
       'ObjdataAd.Fill(objDataSet, "Destinos")
       ObjdataAd.Fill(objDataSet, "Empregados")
       objComm.Dispose()
       objComm = Nothing
       ObjdataAd.Dispose()
       ObjdataAd = Nothing
       objConn.Close()
       objConn.Dispose()
       objConn = Nothing
       Return objDataSet
   End Function

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
       If Match <> -1 And cb1.SelectedIndex = -1 Then
           cb1.SelectedIndex = Match
           Match = -1
       End If

       If cb1.SelectedIndex <> -1 Then
           MsgBox("Numero: " & cb1.SelectedValue & " com o nome " &
cb1.GetItemText(cb1.SelectedItem))
           MsgBox("Indice: " & cb1.SelectedIndex)
       End If
       
       cb1.SelectedIndex = -1

   End Sub

To resolve this issue I populate the combo again. But this makes the
application slower.

There’s anyone who knows to resolve this little problem?

Thanks to all.

Ana Rita
Herfried K. Wagner [MVP] - 03 Sep 2004 13:12 GMT
* "=?Utf-8?B?QW5hIFJpdGE=?=" <Ana Rita@discussions.microsoft.com> scripsit:
> I’m populating the combo with a dataset. I set its ValueMenber and
> DisplayMenber, and the selectedindex to -1. The dropdownstyle is set to
[quoted text clipped - 3 lines]
> the selectedIndex that the combo assume is 0, therefore it show its first
> value.

That's a known bug:

BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
<URL:http://support.microsoft.com/?scid=kb;EN-US;327244>

Signature

M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://dotnet.mvps.org/dotnet/faqs/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.