private void ListBoxSubjects_SelectedValueChanged(object sender, EventArgs e) { Subject selected = (Subject)listBoxSubjects.SelectedItem; if (selected == null) { return; } textBoxNotes.Text = selected.SubjectStates[selected.SubjectStates.Count - 1].Notes; SQLiteManager manager = new SQLiteManager(); manager.Connect(); using (manager.connection) { adapter = new SQLiteDataAdapter($"SELECT [LastVisit] AS [időpont], [Stnr] AS [STNR], [Atnr] AS [ATNR], [Galant], [TlRH] AS [TLRH], [Ejto] AS [Ejtőe.], [Tlre] AS [TLRE], [Schilder] AS [Schild.], [Babinski] AS [Bab.], [Mar] AS [markoló], [Szo] AS [szopó], [Mor] AS [Moro], [Niszt] AS [Nyst.], [Left] AS [bal], [Right] AS [jobb] FROM [SubjectState] WHERE [SubjectId] = {selected.Id} ORDER BY [SubjectState].[LastVisit]", manager.connection); DataTable table = new DataTable(); adapter.Fill(table); dataGridView1.DataSource = table; int totalRowHeight = dataGridView1.ColumnHeadersHeight; foreach (DataGridViewRow row in dataGridView1.Rows) { totalRowHeight += row.Height; } dataGridView1.Height = totalRowHeight; } }