CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2006
    Posts
    6

    Combo box problem

    Hie..i have this problem that i do not understand. Below are my codes. The problem is whenever i set the data retrieved from database to the controls. Only some of the combo box display the data. What i do not understand is IF i change the combo box drop down style from "drop down list" to "drop down" it worked! . I dont want the user to tamper with the data displayed in the combo box. Plz help. TQ

    Dim conn As New OracleConnection(refDB)
    Try
    conn.Open()

    Dim cmd As New OracleCommand
    Dim retValue As String
    cmd.Connection = conn

    cmd.CommandText = "select * from ME_PIPE_INDEX where ME_NUMBER = '" & Trim(txtMEno.Text.ToUpper) & "'"
    cmd.CommandType = CommandType.Text

    Dim dr As OracleDataReader = cmd.ExecuteReader()

    If dr.Read() Then

    retValue = Trim(dr("ME_NUMBER"))

    If retValue = txtMEno.Text.ToUpper Then
    cboType.Text = (dr("ME_NUM3_DESC"))
    cboLMC.Text = (dr("ME_NUM4_DESC"))
    txtRemCode.Text = (dr("ME_NUM5678"))
    cboDescMaterial.Text = (dr("MAT_DESC"))
    cboConst.Text = (dr("CONST_DESC"))
    cboDescSch.Text = (dr("SCHEDULE_DESC"))
    cboDescEndPrep.Text = (dr("END_PREP_DESC"))
    lblMaterialCode.Text = (dr("ME_NUMBER"))
    lblDesc.Text = (dr("DESCRIPTION"))
    txtID.Text = (dr("ME_PIPE_ID"))
    btnDelete.Enabled = True

    Else
    MsgBox(" ME Number Doesn't Exist ", vbCritical, "Error Searching")
    End If
    Else
    MsgBox(" Job Doesn't Exist ", vbCritical, "Error Searching")
    End If

    Catch ex As OracleException ' catches only Oracle errors
    Select Case ex.Number
    Case 1
    MessageBox.Show("Error attempting to insert duplicate data.")
    Case 12545
    MessageBox.Show("The database is unavailable.")
    Case Else
    MessageBox.Show("Database error: " + ex.Message.ToString())
    End Select

    Catch ex As Exception ' catches any error
    MessageBox.Show(ex.Message.ToString())

    Finally
    conn.Dispose()

    End Try

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,284

    Re: Combo box problem

    Hello!
    I'm gonna take a very wild guess.
    I think the problem might be that you're referring to the text property of the combobox. Like:
    Code:
    cboType.Text = (dr("ME_NUM3_DESC"))
    cboLMC.Text = (dr("ME_NUM4_DESC"))
    cboDescMaterial.Text = (dr("MAT_DESC"))
    cboConst.Text = (dr("CONST_DESC"))
    cboDescSch.Text = (dr("SCHEDULE_DESC"))
    cboDescEndPrep.Text = (dr("END_PREP_DESC"))
    Why not try the SelectedItem property of the comboboxes

    As I've said, it's just a guess ,but I sincerely hope it helps a bit!

  3. #3
    Join Date
    Oct 2005
    Location
    Islamabad, Pakistan
    Posts
    1,277

    Re: Combo box problem

    try selectedIndex property of comboBox
    Code:
      Dim a() As String = {"Anis", "Khan", "AnisKhan"}
            Me.ComboBox1.Items.AddRange(a)
            Me.ComboBox1.SelectedIndex = 0
    Last edited by aniskhan; February 20th, 2006 at 04:00 PM.

  4. #4
    Join Date
    Feb 2006
    Posts
    6

    Re: Combo box problem

    Quote Originally Posted by HanneSThEGreaT
    Hello!
    I'm gonna take a very wild guess.
    I think the problem might be that you're referring to the text property of the combobox. Like:
    Code:
    cboType.Text = (dr("ME_NUM3_DESC"))
    cboLMC.Text = (dr("ME_NUM4_DESC"))
    cboDescMaterial.Text = (dr("MAT_DESC"))
    cboConst.Text = (dr("CONST_DESC"))
    cboDescSch.Text = (dr("SCHEDULE_DESC"))
    cboDescEndPrep.Text = (dr("END_PREP_DESC"))
    Why not try the SelectedItem property of the comboboxes

    As I've said, it's just a guess ,but I sincerely hope it helps a bit!
    Nope it doesnt work...i've tried changing it to .SelectedItem but the same problem occurs :-( . I'm confused that some of the combobox with the same config (DropDownList - style) works and some don't. All of them will work if i changed the style to 'DropDown' it's just that i don't want the user to miskey the wrong information as DropDown style allows modification.
    Last edited by jep2002; February 22nd, 2006 at 02:43 AM.

  5. #5
    Join Date
    Aug 2004
    Posts
    391

    Re: Combo box problem

    If the problem is not letting the use tamper with data displayed, here is a quick fix.

    Use the key press even of the combo box and negate any data entered by user byone lien of code

    type into keypress event
    e.cancel = true

    this will prevent user from changing any data in your combo box making your combo virtually read only.

    Sorry i jsut had tiem to skim through problem.

    Hope this helped.

  6. #6
    Join Date
    Aug 2004
    Posts
    391

    Re: Combo box problem

    sorry it is e.handled = true

  7. #7
    Join Date
    Feb 2006
    Posts
    6

    Re: Combo box problem

    Thank you all for your help..i've found the solution for the problem. I've change it using .selecteditem n at first it didn't work. It seems that actually when i populate the combo box at the first place i didn't trim the data, so when i compare it cboType.Text = (dr("ME_NUM3_DESC")) for example, the data in the combo box doesn't match with the one that is retrieved from the DB (because it contains spaces)...Thanx again :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured