Visual Basic - Mantener Iten en combobox

Life is soft - evento anual de software empresarial
 
Vista:
sin imagen de perfil

Mantener Iten en combobox

Publicado por Josep (25 intervenciones) el 16/02/2017 10:16:06
Buenos dias.
Alguien me puede echar un cable.
En un formulario tengo un combobox llamado desti. Yo selecciono un elemento de este combo. Lo que quiero es que el elemento se muestre siempre pero no lo hace en hacer click en algun otro elemento del formualario me desaparece el elemento seleccionado.
En resumen, yo selecciono un elemento del combo y no quiero que desaparezca en darle al otro control.
Muestro mi codigo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Private Sub Desti_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles Desti.SelectionChangeCommitted
    Dim connectionString As String = Nothing
    Dim connection As SqlConnection
    Dim command As SqlCommand
    Dim adapter As New SqlDataAdapter()
    Dim ds As New DataSet()
    Dim sql As String = Nothing
    Dim id As Integer
 
    id = Desti.SelectedValue
    MessageBox.Show(id)
    connectionString = "Data Source=Josep-Pc\sqlexpress;Initial Catalog=Desplacaments;Integrated Security=SSPI;"
    sql = "SELECT poblacio, km FROM Poblacions WHERE id =" + id.ToString() + ";"
    connection = New SqlConnection(connectionString)
    Try
        connection.Open()
        command = New SqlCommand(sql, connection)
        adapter.SelectCommand = command
        adapter.Fill(ds)
        adapter.Dispose()
        command.Dispose()
        connection.Close()
        Desti.DataSource = ds.Tables(0)
    Catch ex As Exception
        MessageBox.Show("No es pot obrir ")
    End Try
 
    MessageBox.Show(ds.Tables(0).Rows.Count)
    Try
        If ds.Tables(0).Rows.Count = 0 Then
            MessageBox.Show("Oh, no hi ha registres!")
        Else
            'MessageBox.Show(ds.Tables(0).Rows(id - 1).Item(0))
            'Desti.Text = ds.Tables(0).Rows(id - 1).Item(0)
            km.Text = ds.Tables(0).Rows(0).Item(1)
        End If
    Catch ex As Exception
        MessageBox.Show("Error")
    End Try
 
End Sub

Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder