쉼표로 구분 된 파일에서 별개의 데이터를 가져 오는 콤보 상자가 있습니다. 그 별개의 데이터를 사용하고 첫 번째 콤보 상자에 대한 정보 만 포함하는 두 번째 콤보 상자를 채워야합니다. 예 : 여기에 쉼표로 구분 된 파일 텍스트가 있습니다.첫 번째 콤보 상자와 쉼표로 구분 된 파일의 데이터로 두 번째 콤보 상자 채우기
Jenny, 25, Female
Micheal, 100, Female, hdfgh
shaun, 50, male
Cindy, 75, Female
Jenny, 25, Female
Micheal, 100, Female
shaun, 50, male
Cindy, 50, Female
Carry, 75, Female
그리고 여기 내 코드입니다 : 이것은 각 콤보로 구별 데이터를 채우기 위해 잘 작동
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call combo1()
Call combo2()
End Sub
Sub combo1()
' a set to store the names
Dim names = New HashSet(Of String)
Using reader = New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\here.txt")
reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
reader.Delimiters = New String() {","}
Dim currentRow As String()
While Not reader.EndOfData
Try
' read rows and add first field to set
currentRow = reader.ReadFields()
names.Add(currentRow(0).ToString())
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
' do something
End Try
End While
End Using
' bind data to combo box (or use Items.Add instead)
ComboBox1.DataSource = names.ToList()
End Sub
Sub combo2()
' a set to store the names
Dim names = New HashSet(Of String)
Using reader = New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\here.txt")
reader.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
reader.Delimiters = New String() {","}
Dim currentRow As String()
While Not reader.EndOfData
Try
' read rows and add first field to set
currentRow = reader.ReadFields()
names.Add(currentRow(1).ToString())
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
' do something
End Try
End While
End Using
' bind data to combo box (or use Items.Add instead)
ComboBox2.DataSource = names.ToList()
End Sub
,하지만 난 경우에만, 콤보 1 예를 선택한 항목의 데이터를 채우려면 두 번째 콤보 상자를 원한다 내가 선택한 "신디"다음 콤보 박스는 25와 75 만 보여야 만한다.
중복 가능성에 아이디어를
쓰기 승인 코드를 얻을 데이터베이스 대신 쉼표로 구분 된 파일에서?] (http://stackoverflow.com/questions/18468627/visual-basic-how-to-add-a-destinct-combobox-from-a-comma-delimited-file -instead) –
@KenWhite 아니오,이 질문은 다릅니다. 당신이 언급하는 질문에 대한 답을 얻습니다. 여기서 nikki는 첫 번째 선택된 행을 기반으로 두 번째 콤보 박스를 바인딩해야합니다. – inquisitive
기본적으로 두 번째 콤보 상자를 채울 필요가 있지만 첫 번째 콤보 상자를 선택한 값과 관련하여 행을 선택하면 중복 질문처럼 보일 수 있지만 일치하지는 않습니다. – Nikki