C
Coderz
I have created this code using VB.NET 2003 version and wondering how
can I use this with v2008 using datagridview. Since this code is using
datagrid and not datagridview how can I convert this to v2008?
here's the code:
Dim hti As DataGrid.HitTestInfo =
Me.dgSchYrSem.HitTest(e.X, e.Y)
Try
If hti.Type = DataGrid.HitTestType.Cell AndAlso
hti.Column = myCheckBoxCol Then
Me.dgSchYrSem(hti.Row, hti.Column) = Not
CBool(Me.dgSchYrSem(hti.Row, hti.Column))
Dim rowNum As Integer =
dgSchYrSem.CurrentCell.RowNumber
Dim SchYrSemIDValue As Integer =
dgSchYrSem(rowNum, 0)
Dim intProgramID As Integer =
cboProgram.Tag.ToString
Dim intMajorID As Integer =
getMajorID(dgSchYrSem(rowNum, 5))
Dim SemValue As String = dgSchYrSem(rowNum, 2)
Dim YearValue As Integer = dgSchYrSem(rowNum, 3)
With dgSchYrSem
.BindingContext(.DataSource,
..DataMember).EndCurrentEdit()
End With
If dgSchYrSem(rowNum, 6) = False Then Exit Sub
Dim SelectedRegularLoadID As Integer
Dim drRegularLoadID() As DataRow =
dsStudentCourse.Tables("RegularLoad").Select("ProgramID = " &
intProgramID & " And MajorID = " & intMajorID & " And Semester = '" &
SemValue & "' And Year = '" & YearValue & "'")
Dim RegularLoadID As DataRow
If drRegularLoadID.Length = 0 Then
MessageBox.Show("No matching record(s)
found.")
Exit Sub
End If
For Each RegularLoadID In drRegularLoadID
SelectedRegularLoadID =
RegularLoadID("RegularLoadID")
Next
Dim drSelectedRegularLoad As DataRow
drSelectedRegularLoad = _
dsStudentCourse.RegularLoad.FindByRegularLoadID
_
(SelectedRegularLoadID)
Dim draRegularLoad As DataRow()
draRegularLoad =
drSelectedRegularLoad.GetChildRows("RegLoadDetails")
Dim drRegularLoadDetails As DataRow
For Each drRegularLoadDetails In draRegularLoad
Dim myTable As DataTable =
dsStudentCourse.Tables("SchYrSemCourseJoin")
Dim myRow As DataRow
myRow = myTable.NewRow()
myRow("SchYrSemID") = SchYrSemIDValue
myRow("CourseID") =
drRegularLoadDetails("CourseID")
myTable.Rows.Add(myRow)
Next
daSchYrSemCourse.Update(dsStudentCourse)
End If
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
This code will autofill datagrid from other table called regularload
and regularloaddetails table based on the criteria in the first
datagrid called dgSchYrSem to the 2nd datagrid called
daSchYrSemCourse.
Please follow this link if if you cannot understand my explanation:
http://sourcecodester.com/images/screenshot.jpg
In the image I have 2 datagrid. The first datagrid contains the column
called regular. If I add a record in this grid and click the checkbox
in regular column the 2nd datagrid will be filled with data
automatically.
Feel free to ask question. Thanks
can I use this with v2008 using datagridview. Since this code is using
datagrid and not datagridview how can I convert this to v2008?
here's the code:
Dim hti As DataGrid.HitTestInfo =
Me.dgSchYrSem.HitTest(e.X, e.Y)
Try
If hti.Type = DataGrid.HitTestType.Cell AndAlso
hti.Column = myCheckBoxCol Then
Me.dgSchYrSem(hti.Row, hti.Column) = Not
CBool(Me.dgSchYrSem(hti.Row, hti.Column))
Dim rowNum As Integer =
dgSchYrSem.CurrentCell.RowNumber
Dim SchYrSemIDValue As Integer =
dgSchYrSem(rowNum, 0)
Dim intProgramID As Integer =
cboProgram.Tag.ToString
Dim intMajorID As Integer =
getMajorID(dgSchYrSem(rowNum, 5))
Dim SemValue As String = dgSchYrSem(rowNum, 2)
Dim YearValue As Integer = dgSchYrSem(rowNum, 3)
With dgSchYrSem
.BindingContext(.DataSource,
..DataMember).EndCurrentEdit()
End With
If dgSchYrSem(rowNum, 6) = False Then Exit Sub
Dim SelectedRegularLoadID As Integer
Dim drRegularLoadID() As DataRow =
dsStudentCourse.Tables("RegularLoad").Select("ProgramID = " &
intProgramID & " And MajorID = " & intMajorID & " And Semester = '" &
SemValue & "' And Year = '" & YearValue & "'")
Dim RegularLoadID As DataRow
If drRegularLoadID.Length = 0 Then
MessageBox.Show("No matching record(s)
found.")
Exit Sub
End If
For Each RegularLoadID In drRegularLoadID
SelectedRegularLoadID =
RegularLoadID("RegularLoadID")
Next
Dim drSelectedRegularLoad As DataRow
drSelectedRegularLoad = _
dsStudentCourse.RegularLoad.FindByRegularLoadID
_
(SelectedRegularLoadID)
Dim draRegularLoad As DataRow()
draRegularLoad =
drSelectedRegularLoad.GetChildRows("RegLoadDetails")
Dim drRegularLoadDetails As DataRow
For Each drRegularLoadDetails In draRegularLoad
Dim myTable As DataTable =
dsStudentCourse.Tables("SchYrSemCourseJoin")
Dim myRow As DataRow
myRow = myTable.NewRow()
myRow("SchYrSemID") = SchYrSemIDValue
myRow("CourseID") =
drRegularLoadDetails("CourseID")
myTable.Rows.Add(myRow)
Next
daSchYrSemCourse.Update(dsStudentCourse)
End If
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
This code will autofill datagrid from other table called regularload
and regularloaddetails table based on the criteria in the first
datagrid called dgSchYrSem to the 2nd datagrid called
daSchYrSemCourse.
Please follow this link if if you cannot understand my explanation:
http://sourcecodester.com/images/screenshot.jpg
In the image I have 2 datagrid. The first datagrid contains the column
called regular. If I add a record in this grid and click the checkbox
in regular column the 2nd datagrid will be filled with data
automatically.
Feel free to ask question. Thanks