Visual Basic.NET - Problemas con un ComboBox

 
Vista:
sin imagen de perfil
Val: 344
Bronce
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Problemas con un ComboBox

Publicado por Miguel (281 intervenciones) el 14/01/2017 14:10:36
Tengo un formulario con un ComboBox. tengo dos campos del formulario que cada vez que entro en uno de ellos me carga un fichero de texto del que selecciono una opción del mismo. Entro en el primero y capturo el item que quiero. El problema que entro en el segundo campo y me coge los valores del fichero txt anterior.
Les dejo el código pues yo estoy desmoralizado ya que no doy con el problema.

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
42
43
44
45
46
47
Private Sub txtEstado_GotFocus(sender As Object, e As EventArgs) Handles txtEstado.GotFocus
Dim miFichero As String = "C:\Ficheros\Estado.txt"
Me.ClientSize = New System.Drawing.Size(950, 640)
Me.cbDatos.Items().Clear()
cargacbBox(miFichero)
End Sub
 
Private Sub txtEsposo_GotFocus(sender As Object, e As EventArgs) Handles txtEsposo.GotFocus
Dim miFichero As String = "C:\Ficheros\Relacion.txt"
Me.ClientSize = New System.Drawing.Size(950, 640)
Me.cbDatos.Items().Clear()
cargacbBox(miFichero)
End Sub
 
Private Sub cargacbBox(ByVal miFichero As String)
Dim sLine As String = ""
Dim objReader As New StreamReader(miFichero)
If My.Computer.FileSystem.FileExists(miFichero) Then
Select Case miFichero
Case "C:\Ficheros\Estado.txt"
miNume = 1
Case "C:\Ficheros\Relacion.txt"
miNume = 2
End Select
Do
sLine = objReader.ReadLine()
If Not sLine Is Nothing Then
cbDatos.Items.Add(sLine)
End If
Loop Until sLine Is Nothing
objReader.Close()
Else
MsgBox("File not found.")
End If
End Sub
 
Private Sub cbDatos_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbDatos.SelectedIndexChanged
Select Case miNume
Case 1
txtEstado.Text = cbDatos.SelectedItem.ToString
txtEsposo.Focus()
Case 2
txtEsposo.Text = cbDatos.SelectedItem.ToString
txtHijos.Focus()
End Select
Me.ClientSize = New System.Drawing.Size(735, 640)
End Sub

Espero que alguien pueda indicarme el error.

Gracias y un saludo
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
sin imagen de perfil

Problemas con un ComboBox

Publicado por arbol (166 intervenciones) el 14/01/2017 14:18:37
Saludos buen dia

instala el anydesck enviame el id y te gui como resolver tu problema

estare a tus ordenes
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
-3
Comentar
Imágen de perfil de Carlos Castro

Problemas con un ComboBox

Publicado por Carlos Castro (37 intervenciones) el 15/01/2017 03:58:18
En el visual studio 2013 funciona....pero cuando pierde el foco Leave antiguamente LostFocus

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
42
43
44
45
46
47
48
49
50
51
52
53
54
Imports System.IO
Public Class Form1
    Dim miNume As Integer
    Private Sub txtEstado_Leave(sender As Object, e As EventArgs) Handles txtEstado.Leave
        Dim miFichero As String = "C:\Ficheros\Estado.txt"
        Me.ClientSize = New System.Drawing.Size(950, 640)
        Me.cbDatos.Items().Clear()
        cargacbBox(miFichero)
 
    End Sub
 
    Private Sub txtEsposo_Leave(sender As Object, e As EventArgs) Handles txtEsposo.Leave
        Dim miFichero As String = "C:\Ficheros\Relacion.txt"
        Me.ClientSize = New System.Drawing.Size(950, 640)
        Me.cbDatos.Items().Clear()
        cargacbBox(miFichero)
    End Sub
 
    Private Sub cbDatos_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbDatos.SelectedIndexChanged
        Select Case miNume
            Case 1
                txtEstado.Text = cbDatos.SelectedItem.ToString
                txtEsposo.Focus()
            Case 2
                txtEsposo.Text = cbDatos.SelectedItem.ToString
                txtHijos.Focus()
        End Select
        Me.ClientSize = New System.Drawing.Size(735, 640)
    End Sub
 
    Private Sub cargacbBox(ByVal miFichero As String)
        Dim sLine As String = ""
        Dim objReader As New StreamReader(miFichero)
        If My.Computer.FileSystem.FileExists(miFichero) Then
            Select Case miFichero
                Case "C:\Ficheros\Estado.txt"
                    miNume = 1
                Case "C:\Ficheros\Relacion.txt"
                    miNume = 2
            End Select
            Do
                sLine = objReader.ReadLine()
                If Not sLine Is Nothing Then
                    cbDatos.Items.Add(sLine)
                End If
            Loop Until sLine Is Nothing
            objReader.Close()
        Else
            MsgBox("File not found.")
        End If
    End Sub
 
 
End Class
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 344
Bronce
Ha mantenido su posición en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

Problemas con un ComboBox

Publicado por Miguel (281 intervenciones) el 16/01/2017 13:47:01
Ya pueden disculparme por el tiempo que puedan haber perdido con la consulta. Decirles que funciona correctamente solo fue un despiste en el contenido de los ficheros de texto, los cuales duplique pero no cambie el contenido. Después de varios días pensando en el error y viendo que tenía bien planteado el código es cuando me dio por revisar los ficheros. Hay es donde tenía el error.

Mil perdones y muchas gracias.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar