vb Code:
Public Sub LoadDataGridView() Connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DatabaseName) Connection.Open() Adapter.SelectCommand = New OleDbCommand("SELECT * FROM [Students]") Adapter.SelectCommand.Connection = Connection DS = New DataSet() Adapter.Fill(DS) Connection.Close() With frmStudents Dim DT As DataTable = DS.Tables(0) .dgvStudents.DataSource = DT .dgvStudents.Columns.Item(0).Visible = False End With End Sub
Here's what my current code is. As you see it selects * from students and then fills it into the DataSource.
now heres the code that gets the selected index and selects the DataGridView and Combo Box Index
vb Code:
Public Sub SyncDGVAndCombo() With frmStudents Connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DatabaseName) Connection.Open() Adapter.SelectCommand = New OleDbCommand("SELECT [CIndex] FROM [Students]") Adapter.SelectCommand.Connection = Connection DS = New DataSet() Adapter.Fill(DS) Connection.Close() 'RINDEX = the e.RowIndex And/Or cmb.SelectedIndex .dgvStudents.Rows(.RIndex).Selected = True .tscbStudents.SelectedIndex = .dgvStudents.Rows.Item(.RIndex).Index End With End Sub
Now what needs to be done, or what I'm trying to accomplish, is when the user clicks on a column, it gets sorted to alphabetical order.
When I click on A and its in Index 0 but when I click on the Name Column it in the Index of 3. BUT when I click the Row 3, to call the Sync Code, it gets the Data From Index 3 (C), instead of (A). So. How would I get the Value from CIndex which I Hide(its the Column, Match it up the Row in the Database then retrieve the Data from the Appropriate Row)




Reply With Quote