Autofill datagridview using the criteria

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
 
M

Michel Posseth

Coderz said:
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



JTBS

Did you know that the datagrid is still usable for the forseeing future ?
( in fact it isn`t declared obsolete AFAIK )
right click on the toolbox , choose add items and select the datgrid , this
works also in 2008 of VS.Net
and i guess even in the CTP of VS.Net 2010 as the datgrid is part of the
framework

Just that MS decided to favor the datgridview above the datagrid in it`s
IDE toolbox as standard item doesn`t mean you can not use it annymore
you might discover awhole bunch of other controls that might be handy , if
MS had to put them all standard on the toolbox window this would probably
mean a lot of claims for RSI injury`s :)


regards

Michel Posseth
 
C

Cor Ligthert[MVP]

Coderz,

The datagrid and the datagridview are two almost totally diferent verhicles.
(Beside the name)

Cor
 
C

Coderz

Yes you are right but datagrid would be the same like DAO before. It
is retain for backward compatibility and ADO replaces DAO totally.

Here's the notes from MS help

The DataGridView control replaces and adds functionality to the
DataGrid control; however, the DataGrid control is retained for both
backward compatibility and future use, if you choose. For more
information, see Differences Between the Windows Forms DataGridView
and DataGrid Controls.

and

The DataGridView control is a new control that replaces the DataGrid
control. The DataGridView control provides numerous basic and advanced
features that are missing in the DataGrid control. Additionally, the
architecture of the DataGridView control makes it much easier to
extend and customize than the DataGrid control.

You can find it in your help file at this url:
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/dv_fxmclictl/html/d412c786-140e-4210-8a56-a68467530a55.htm

When I upgrade my 2003 version of my source code it is still working
with 2008 version but what I like most with the new datagrid (aka
datagridview) is the ability to add a combobox directly without having
to code a combobox inside a grid.

I have a lot of source code that I am planning to upgrade from vb 6.0
to vb.net and I want to use datagridview for easy manipulation of any
controls like datapicker, combobox, checkbox, buttons inside the
datagridview.

This control would likely be very helpful if I upgrade my one of my
source code like hotel reservation at
http://www.sourcecodester.com/visual-basic/hotel-reservation-software.html.

Enrollment system will be available for free also at
www.sourcecodester.com after I finish coding this autofill feature
that I like.

Thanks
 
C

Coderz

Coderz,

The datagrid and the datagridview are two almost totally diferent verhicles.
(Beside the name)

Cor

Yes you are right. I hope somebody can help me out of this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top