emaduddeen
Well-known member
- Joined
- May 5, 2010
- Messages
- 171
- Location
- Lowell, MA & Occasionally Indonesia
- Programming Experience
- Beginner
Greeting Everyone.
I have a few questions.
First one is: How do you refresh a datagrid without it loosing focus?
Currently this is the code I use to get data into the datagrid:
Once the data is loaded in the grid the application will delete, insert or update the database.
At that point I issue a call to the subprocedure with InitializeTheDataGrid.
The line of code that makes the datagrid to loose focus is LightGridAttendance.DataSource = objDataTable
Is there any way to stop it from loosing focus?
The other question is that since I'm rather new to VB 2008 I'm using the "New" keyword in many places such as objDataAdapter = New OleDbDataAdapter(strSqlStatement, objConnection)
Will the application eventually use up some kind of limit by repeated use of the "New" keyword?
I also use LightGridAttendance.Focus() to get focus on the datagrid but I think that statement does not work with datagrids. Nothing happens.
Is there a way to refresh the datagrid data without using LightGridAttendance.DataSource = objDataTable ?
All help will be greatly appreciated.
Truly,
Emad
I have a few questions.
First one is: How do you refresh a datagrid without it loosing focus?
Currently this is the code I use to get data into the datagrid:
VB.NET:
Private Sub InitializeTheDataGrid()
' Declare strings to hold SQL Statements.
'----------------------------------------
strSqlStatement = _
"SELECT attendance.AttendanceID, " & _
"class.ClassID, " & _
"class.ClassName, " & _
"Student.StudentId, " & _
"LTrim(Student.FirstName) & ' ' & LTrim(Student.LastName) AS [Student Name], " & _
"Int((Date()-dob)/365.25) AS StudentAge, " & _
"Parent.HomePhone, " & _
"Parent.Email, " & _
"attendance.DateOfClass, " & _
"attendance.Absent, " & _
"class.GradeID " & _
"FROM (Class INNER JOIN " & _
"(Attendance INNER JOIN Student ON Attendance.StudentID = Student.StudentId) " & _
"ON Class.ClassId = Attendance.ClassId) INNER JOIN Parent ON Student.ParentId = Parent.ParentId"
Try
' Create the connection object to use an SQL query and open it.
'--------------------------------------------------------------
objConnection = New OleDbConnection(My.Settings.ISGL_Database)
objConnection.Open()
' Create a DataTable object to hold data from the SQL query.
'-----------------------------------------------------------
objDataTable = New DataTable()
' Create a DataAdapter object for the DataTable.
'-----------------------------------------------
objDataAdapter = New OleDbDataAdapter(strSqlStatement, objConnection)
' Load the DataAdapter with the data from the DataTable SQL query.
'-----------------------------------------------------------------
objDataAdapter.Fill(objDataTable)
' Load the data into the grid.
'-----------------------------
LightGridAttendance.DataSource = objDataTable
Finally
' Close the connection if it's currently open.
'---------------------------------------------
If objConnection IsNot Nothing Then
objConnection.Close()
End If
End Try
End Sub
Once the data is loaded in the grid the application will delete, insert or update the database.
At that point I issue a call to the subprocedure with InitializeTheDataGrid.
The line of code that makes the datagrid to loose focus is LightGridAttendance.DataSource = objDataTable
Is there any way to stop it from loosing focus?
The other question is that since I'm rather new to VB 2008 I'm using the "New" keyword in many places such as objDataAdapter = New OleDbDataAdapter(strSqlStatement, objConnection)
Will the application eventually use up some kind of limit by repeated use of the "New" keyword?
I also use LightGridAttendance.Focus() to get focus on the datagrid but I think that statement does not work with datagrids. Nothing happens.
Is there a way to refresh the datagrid data without using LightGridAttendance.DataSource = objDataTable ?
All help will be greatly appreciated.
Truly,
Emad