It is the last statement in the sub so it really doesn't affect the function. But the CurrentCell.Selected statement transfers control out of the routine. Why? The ActiveControl / CurrentCell.Selected pair are there to remove the highlighting in the top left cell of the datagridview. It took me some googling to figure that out. (Most of the code samples I found didn't work.) If I comment out the CurrenCell.Selected control continues through to End Sub. I have included a few statements above for context. Is there another way to clear the highlighting?
Code:Dim da As New OleDbDataAdapter(strSQL, dbConnection) Dim dt As New DataTable Try dbConnection.Open() Catch exc As OleDbException MsgBox(exc.Message) End Try da.Fill(dt) da.Dispose() DataGridView1.DataSource = dt dbConnection.Close() NumRecsTextBox.Text = CStr(dt.Rows.Count) dt = Nothing da = Nothing DataGridView1.Columns(0).Visible = False ActiveControl = ExitButton() DataGridView1.CurrentCell.Selected = False <---------------- This statement transfers control out of the routine End Sub




Reply With Quote