It doesn't matter what kind of control you use to display data, whether it's a datagrid or listview, both work fine and it all depends on how you want them to look. So I'm taking the liberty to say that your question really is about querying data against the different tables and showing it on a list. This is purely SQL.
Your table Departments_Subjects_junction
cannot have both fields under it as primary keys since the way I see it, it's the table that defines what subjects a certain department has. So it should be...
Departments_Subjects_junction
department_id(primary key)
subject_id
Then you can query using this SQL statement...
SELECT T2.department_name, T3.subject_name
FROM Departments_Subjects_junction T1
INNER JOIN Departments T2
ON T1.department_id=T2.department_id
INNER JOIN Subjects T3
ON T1.subject_id=T3.subject_id;
Okay here's what you'll have to do...
1) Add a ListView
control to your form.
2) Add a single column during design time.
3) Set the ListView's View
Property to Details
.
4) Add this code anywhere and just call it.
Private Sub displaydata()
Dim item As ListViewItem
Dim dt As New DataTable
dt.Clear()
ListView1.Groups.Clear()
da = New SqlDataAdapter("SELECT department_name FROM Departments", con)
da.Fill(dt)
For x = 0 To dt.Rows.Count - 1
ListView1.Groups.Add(dt.Rows(x).Item("department_name"), dt.Rows(x).Item("department_name"))
Next x
dt.Clear()
ListView1.Items.Clear()
da = New SqlDataAdapter("SELECT T2.department_name, T3.subject_name FROM Departments_Subjects_junction T1 INNER JOIN Departments T2 ON T1.department_id=T2.department_id INNER JOIN Subjects T3 ON T1.subject_id=T3.subject_id ", con)
da.Fill(dt)
For x = 0 To dt.Rows.Count - 1
item = New ListViewItem
item.Text = dt.Rows(x).Item("subject_name")
item.Group = ListView1.Groups(dt.Rows(x).Item("department_name"))
ListView1.Items.Add(item)
Next x
dt.Clear()
End Sub
This should work.