Reputation: 29
I have an access databasetable with addresses and a table with addresstypes. When i add a new relation there's different groupboxes with additional information that should be displayed according to the addresstype. For example: a patient has only basic address info. A doctor needs a reference number too, so if i click on relation type "doctor" the address groupbox should appear but also the groupbox with doctor reference textbox. An instance should also get the instance groupbox + address groupbox etc etc. Addresses can also be "multiple types" so if an address is A: a doctor, and B an instance, both boxes should appear. My current code looks like this:
Public Class NewRelationForm
'groupboxen disablen on load
Me.grpKiesUwRelatietype.Visible = True
Me.grpBasisData.Visible = False
Me.grpDataBI.Visible = False
Me.grpFoto_Nota.Visible = False
Me.grpHuisartsData.Visible = False
Me.grpPartijData.Visible = False
Me.grpVerwijzerdata.Visible = False
End Sub
'KNOPPEN en Functies!
Private Sub NewRelationForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Tbl_TypeTableAdapter1.Fill(Me.PatientenDatabaseDataSetX1.tbl_Type)
Me.Tbl_OnderzoeksTypesTableAdapter.Fill(Me.PatientenDatabaseDataSetX1.tbl_OnderzoeksTypes)
Me.Tbl_RelatiesTableAdapter.Fill(Me.PatientenDatabaseDataSetX.tbl_Relaties)
End Sub
Private Sub btnAddRelation_Click(sender As Object, e As EventArgs) Handles btnAddRelation.Click
FormMakeRelationType.Show()
End Sub
Private Sub lboxRelatieTypes_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lboxRelatieTypes.SelectedIndexChanged
End Sub
'Private Sub lboxRelatieTypes_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lboxRelatieTypes.SelectedIndexChanged
''If ComboBox1.SelectedIndex = 1 Then
'' grpBasisData.Visible = True
'' grpFoto_Nota.Visible = True
'' grpFoto_Nota.Location = New Point(720, 120)
''End If
'End Sub
End Class
I could really use a pointer in how to do this, i've tried if else, i've tried select case, but i can't find "the right way". I'm a beginner edit1: This is a pic from the winform: https://i.sstatic.net/uYexM.jpg and this is the access db (names in the db are changed for privacy purposes https://www.dropbox.com/sh/4gudk8lwxtjahiq/AACz69ocFWIlU7hiTlQxbviLa?dl=0
Upvotes: 0
Views: 162
Reputation: 29
I found it... based on an article in stackoverflow: How to show hidden text boxes when items are selected in a combo box
If someone knows how to make this piece of code "easier to handle" or "more compact" i'm very open to ideas. Also: i can only select one , the rest of the groupboxes dissappear , so it needs some finetuning but i'm 90% there!
Private Sub lboxRelatieTypes_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lboxRelatieTypes.SelectedIndexChanged
If lboxRelatieTypes.Text.Trim.Contains("Patiënt") = True Then
Me.grpBasisData.Visible = True
Me.grpDataBI.Visible = False
Me.grpFoto_Nota.Visible = True
Me.grpHuisartsData.Visible = False
Me.grpPartijData.Visible = False
Me.grpVerwijzerdata.Visible = False
ElseIf lboxRelatieTypes.Text.Trim.Contains("Verwijzer") = True Then
Me.grpBasisData.Visible = True
Me.grpDataBI.Visible = False
Me.grpFoto_Nota.Visible = True
Me.grpHuisartsData.Visible = False
Me.grpPartijData.Visible = False
Me.grpVerwijzerdata.Visible = True
ElseIf lboxRelatieTypes.Text.Trim.Contains("Betalende Instantie") = True Then
Me.grpBasisData.Visible = True
Me.grpDataBI.Visible = True
Me.grpFoto_Nota.Visible = True
Me.grpHuisartsData.Visible = False
Me.grpPartijData.Visible = True
Me.grpVerwijzerdata.Visible = False
ElseIf lboxRelatieTypes.Text.Trim.Contains("Huisarts") = True Then
Me.grpBasisData.Visible = True
Me.grpDataBI.Visible = False
Me.grpFoto_Nota.Visible = True
Me.grpHuisartsData.Visible = True
Me.grpPartijData.Visible = False
Me.grpVerwijzerdata.Visible = False
ElseIf lboxRelatieTypes.Text.Trim.Contains("Huisarts" & "Betalende Instantie") = True Then
Me.grpBasisData.Visible = True
Me.grpDataBI.Visible = True
Me.grpFoto_Nota.Visible = True
Me.grpHuisartsData.Visible = True
Me.grpPartijData.Visible = False
Me.grpVerwijzerdata.Visible = False
End If
'Dim curitem As String = lboxRelatieTypes.SelectedItems.ToString()
'Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=F:\GoogleDrive\EINDWERK VBNET\PatientenDatabase.accdb")
'con.Open()
'Dim sql As String = String.Format("select * from tbl_Relaties where Rel_Type='{0}'", curitem)
'Dim command As New OleDbCommand(sql, con)
'Dim reader As OleDbDataReader = command.ExecuteReader()
'If curitem.Contains "Huisarts" Then
' End If
'con.Close()
Upvotes: 1
Reputation: 5986
I make a code example, which show the textbox in the groupbox based on the listbox.
Form_Load event:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\PatientenDatabase.mdb")
con.Open()
Dim sql As String = "select Type_Naam from tbl_type"
Dim command As New OleDbCommand(sql, con)
Dim reader As OleDbDataReader = command.ExecuteReader()
While reader.Read()
ListBox1.Items.Add(reader.GetString(0))
End While
con.Close()
End Sub
Listboxindexchanged event:
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Dim curItem As String = ListBox1.SelectedItem.ToString()
Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\PatientenDatabase.mdb")
con.Open()
Dim sql As String = String.Format("select * from tbl_Relaties where Rel_Type='{0}'", curItem)
Dim command As New OleDbCommand(sql, con)
Dim reader As OleDbDataReader = command.ExecuteReader()
If reader.HasRows Then
While reader.Read()
txtID.Text = reader.GetValue(0).ToString()
txtType.Text = reader.GetValue(1).ToString()
txtName.Text = reader.GetValue(2).ToString()
txtVoo.Text = reader.GetValue(3).ToString()
txtAdress.Text = reader.GetValue(4).ToString()
End While
Else
txtID.Text = String.Empty
txtType.Text = String.Empty
txtName.Text = String.Empty
txtVoo.Text = String.Empty
txtAdress.Text = String.Empty
End If
con.Close()
End Sub
Final result:
Besides, I only make a few column code and you can follow the above code to complete the rest of the code.
Upvotes: 0