Click to See Complete Forum and Search --> : Combo box problem


jep2002
February 20th, 2006, 02:29 AM
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

HanneSThEGreaT
February 20th, 2006, 07:17 AM
Hello! :wave:
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:
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!

aniskhan
February 20th, 2006, 02:57 PM
try selectedIndex property of comboBox
Dim a() As String = {"Anis", "Khan", "AnisKhan"}
Me.ComboBox1.Items.AddRange(a)
Me.ComboBox1.SelectedIndex = 0

jep2002
February 22nd, 2006, 01:39 AM
Hello! :wave:
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:
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.

venAdder
February 22nd, 2006, 06:12 PM
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.

venAdder
February 22nd, 2006, 07:30 PM
sorry it is e.handled = true

jep2002
February 24th, 2006, 01:22 AM
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 :-)