Hi all i have 2 forms which every form has a datagrid.the 1st form is a datagrid with 4 columns (from,to,grade & points) where i enter the range of scores from students and save them. The second form has a datagrid with 4 columns(subjects,scores,grade & points) where subjects, grade & points are readonly. How can i code the second form when i enter the scores of the subjects to display the grades and points as per the first form automatically?
1 2880
Make Datagridview of Form1 Public so that it can be referenced from Form2 -
Public Partial Class Form1
-
Public DataGridView1 As System.Windows.Forms.DataGridView
-
Public Sub New()
-
' The Me.InitializeComponent call is required for Windows Forms designer support.
-
Me.InitializeComponent()
-
-
'dataGridView1
-
DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
-
DataGridView1.Location = New System.Drawing.Point(126, 228)
-
DataGridView1.Name = "DataGridView1"
-
DataGridView1.RowTemplate.Height = 30
-
DataGridView1.Size = New System.Drawing.Size(896, 540)
-
-
Dim textColumn1 As New DataGridViewTextBoxColumn()
-
Dim textColumn2 As New DataGridViewTextBoxColumn()
-
Dim textColumn3 As New DataGridViewTextBoxColumn()
-
Dim textColumn4 As New DataGridViewTextBoxColumn()
-
textColumn1.DataPropertyName = "From"
-
textColumn1.Name = "From"
-
textColumn1.HeaderText = "From"
-
DataGridView1.Columns.Add(textColumn1)
-
textColumn2.DataPropertyName = "To"
-
textColumn2.Name = "To"
-
DataGridView1.Columns.Add(textColumn2)
-
textColumn3.DataPropertyName = "Grade"
-
textColumn3.Name = "Grade"
-
DataGridView1.Columns.Add(textColumn3)
-
textColumn4.DataPropertyName = "Points"
-
textColumn4.Name = "Points"
-
DataGridView1.Columns.Add(textColumn4)
-
-
DataGridView1.Rows.Add(0, 49, "F", 0)
-
DataGridView1.Rows.Add(50, 59, "E", 1)
-
DataGridView1.Rows.Add(60, 69, "D", 2)
-
DataGridView1.Rows.Add(70, 79, "C", 3)
-
DataGridView1.Rows.Add(80, 89, "B", 4)
-
DataGridView1.Rows.Add(90, 100, "A", 5)
-
-
DataGridView1.Columns(0).ReadOnly = True
-
DataGridView1.Columns(1).ReadOnly = True
-
DataGridView1.Columns(2).ReadOnly = True
-
DataGridView1.Columns(3).ReadOnly = True
-
End Sub
-
End Class
-
-
Public Partial Class Form2
-
Public Sub New()
-
' The Me.InitializeComponent call is required for Windows Forms designer support.
-
Me.InitializeComponent()
-
-
DataGridView1.ColumnCount = 4
-
DataGridView1.AllowUserToAddRows = False
-
DataGridView1.Columns(0).HeaderText = "Subject"
-
DataGridView1.Columns(1).HeaderText = "Score"
-
DataGridView1.Columns(2).HeaderText = "Grade"
-
DataGridView1.Columns(3).HeaderText = "Points"
-
DataGridView1.Rows.Add("Sub1", "", "", 0)
-
DataGridView1.Rows.Add("Sub2", "", "", 0)
-
DataGridView1.Rows.Add("Sub3", "", "", 0)
-
DataGridView1.Rows.Add("Sub4", "", "", 0)
-
DataGridView1.Rows.Add("Aub4", "", "", 0)
-
-
DataGridView1.Columns(0).ReadOnly = True
-
DataGridView1.Columns(1).ReadOnly = False
-
DataGridView1.Columns(2).ReadOnly = True
-
DataGridView1.Columns(3).ReadOnly = True
-
End Sub
-
-
'CellValidated Event
-
Private Sub DataGridView1_CellValidated(ByVal sender As Object, _
-
ByVal e As DataGridViewCellEventArgs)
-
Dim i As Integer
-
Try
-
Dim dgv As DataGridView = DirectCast(sender, DataGridView)
-
Dim columnIndex As Integer = e.ColumnIndex
-
Dim HDNameas As string = dgv.Columns(e.ColumnIndex).HeaderText
-
Dim Row As DataGridViewRow
-
Dim Score As String = Trim(dgv.CurrentCell.Value.ToString)
-
If HDNameas = "Score" AndAlso Score IsNot Nothing AndAlso (Score.Length <> 0) then
-
For Each Row In My.Forms.Form1.datagridview1.Rows()
-
Dim Fromdata As Integer = 0
-
Dim Todata As Integer = 0
-
Dim Points As Integer = 0
-
Dim Grade As String = ""
-
If TypeOf Row.Cells(0).Value Is Integer Then
-
Fromdata = CInt(Row.Cells(0).Value)
-
End If
-
If TypeOf Row.Cells(1).Value Is Integer Then
-
Todata = CInt(Row.Cells(1).Value)
-
End If
-
If TypeOf Row.Cells(2).Value Is String Then
-
Grade = Row.Cells(2).Value.ToString
-
End If
-
If TypeOf Row.Cells(3).Value Is Integer Then
-
Points = CInt(Row.Cells(3).Value)
-
End If
-
If (Grade IsNot Nothing) AndAlso (Grade.Length <> 0) Then
-
Dim SSS As Integer = dgv.CurrentCell.RowIndex
-
If CInt(dgv.CurrentCell.Value.ToString) >= Fromdata AndAlso CInt(dgv.CurrentCell.Value.ToString) <= Todata Then
-
dgv(2, dgv.CurrentCell.RowIndex).Value = Grade
-
dgv(3, dgv.CurrentCell.RowIndex).Value = Points
-
End If
-
End If
-
Next
-
End if
-
Catch ex As Exception
-
MsgBox("Error " & ex.Message , MsgBoxStyle.Critical)
-
End Try
-
End Sub
-
End Class
-
Post your reply Sign in to post your reply or Sign up for a free account.
Similar topics
reply
views
Thread by DraguVaso |
last post: by
|
10 posts
views
Thread by Henok Girma |
last post: by
|
3 posts
views
Thread by Rich |
last post: by
|
2 posts
views
Thread by bob |
last post: by
|
7 posts
views
Thread by Mitchell S. Honnert |
last post: by
|
7 posts
views
Thread by =?Utf-8?B?TG9zdEluTUQ=?= |
last post: by
|
reply
views
Thread by jeastman - Hotmail |
last post: by
|
3 posts
views
Thread by Andrus |
last post: by
| | | | | | | | | | | | |