473,396 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Inputes in datagridview

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?
Aug 31 '18 #1
1 3058
SioSio
272 256MB
Make Datagridview of Form1 Public so that it can be referenced from Form2
Expand|Select|Wrap|Line Numbers
  1. Public Partial Class Form1
  2.     Public DataGridView1 As System.Windows.Forms.DataGridView
  3.     Public Sub New()
  4.         ' The Me.InitializeComponent call is required for Windows Forms designer support.
  5.         Me.InitializeComponent()
  6.  
  7.         'dataGridView1
  8.         DataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize
  9.         DataGridView1.Location = New System.Drawing.Point(126, 228)
  10.         DataGridView1.Name = "DataGridView1"
  11.         DataGridView1.RowTemplate.Height = 30
  12.         DataGridView1.Size = New System.Drawing.Size(896, 540)
  13.  
  14.         Dim textColumn1 As New DataGridViewTextBoxColumn()
  15.         Dim textColumn2 As New DataGridViewTextBoxColumn()
  16.         Dim textColumn3 As New DataGridViewTextBoxColumn()
  17.         Dim textColumn4 As New DataGridViewTextBoxColumn()
  18.         textColumn1.DataPropertyName = "From"
  19.         textColumn1.Name = "From"
  20.         textColumn1.HeaderText = "From"
  21.          DataGridView1.Columns.Add(textColumn1)
  22.         textColumn2.DataPropertyName = "To"
  23.         textColumn2.Name = "To"
  24.          DataGridView1.Columns.Add(textColumn2)
  25.         textColumn3.DataPropertyName = "Grade"
  26.         textColumn3.Name = "Grade"
  27.          DataGridView1.Columns.Add(textColumn3)
  28.         textColumn4.DataPropertyName = "Points"
  29.         textColumn4.Name = "Points"
  30.          DataGridView1.Columns.Add(textColumn4)
  31.  
  32.         DataGridView1.Rows.Add(0, 49, "F", 0)
  33.         DataGridView1.Rows.Add(50, 59, "E", 1)
  34.         DataGridView1.Rows.Add(60, 69, "D", 2)
  35.         DataGridView1.Rows.Add(70, 79, "C", 3)
  36.         DataGridView1.Rows.Add(80, 89, "B", 4)
  37.         DataGridView1.Rows.Add(90, 100, "A", 5)    
  38.  
  39.         DataGridView1.Columns(0).ReadOnly = True
  40.         DataGridView1.Columns(1).ReadOnly = True
  41.         DataGridView1.Columns(2).ReadOnly = True
  42.         DataGridView1.Columns(3).ReadOnly = True
  43.     End Sub
  44. End Class
  45.  
  46. Public Partial Class Form2
  47.     Public Sub New()
  48.         ' The Me.InitializeComponent call is required for Windows Forms designer support.
  49.         Me.InitializeComponent()
  50.  
  51.         DataGridView1.ColumnCount = 4
  52.         DataGridView1.AllowUserToAddRows = False
  53.         DataGridView1.Columns(0).HeaderText = "Subject"
  54.         DataGridView1.Columns(1).HeaderText = "Score"
  55.         DataGridView1.Columns(2).HeaderText = "Grade"
  56.         DataGridView1.Columns(3).HeaderText = "Points"
  57.         DataGridView1.Rows.Add("Sub1", "", "", 0)
  58.         DataGridView1.Rows.Add("Sub2", "", "", 0)
  59.         DataGridView1.Rows.Add("Sub3", "", "", 0)
  60.         DataGridView1.Rows.Add("Sub4", "", "", 0)
  61.         DataGridView1.Rows.Add("Aub4", "", "", 0)
  62.  
  63.         DataGridView1.Columns(0).ReadOnly = True
  64.         DataGridView1.Columns(1).ReadOnly = False
  65.         DataGridView1.Columns(2).ReadOnly = True
  66.         DataGridView1.Columns(3).ReadOnly = True
  67.     End Sub
  68.  
  69. 'CellValidated Event
  70. Private Sub DataGridView1_CellValidated(ByVal sender As Object, _
  71.     ByVal e As DataGridViewCellEventArgs)
  72.     Dim i As Integer
  73.     Try
  74.         Dim dgv As DataGridView = DirectCast(sender, DataGridView)
  75.         Dim columnIndex As Integer = e.ColumnIndex
  76.         Dim HDNameas As string = dgv.Columns(e.ColumnIndex).HeaderText
  77.         Dim Row As DataGridViewRow
  78.         Dim Score As String = Trim(dgv.CurrentCell.Value.ToString)
  79.         If HDNameas = "Score" AndAlso Score IsNot Nothing AndAlso (Score.Length <> 0) then 
  80.             For Each Row In My.Forms.Form1.datagridview1.Rows()
  81.                 Dim Fromdata As Integer = 0
  82.                 Dim Todata As Integer = 0
  83.                 Dim Points As Integer = 0
  84.                 Dim Grade As String = ""
  85.                 If TypeOf Row.Cells(0).Value Is Integer Then
  86.                     Fromdata = CInt(Row.Cells(0).Value)
  87.                 End If
  88.                 If TypeOf Row.Cells(1).Value Is Integer Then
  89.                      Todata = CInt(Row.Cells(1).Value)
  90.                 End If
  91.                 If TypeOf Row.Cells(2).Value Is String Then
  92.                      Grade = Row.Cells(2).Value.ToString
  93.                 End If
  94.                 If TypeOf Row.Cells(3).Value Is Integer Then
  95.                     Points = CInt(Row.Cells(3).Value)
  96.                 End If
  97.                 If (Grade IsNot Nothing) AndAlso (Grade.Length <> 0) Then
  98.                     Dim SSS As Integer = dgv.CurrentCell.RowIndex
  99.                     If CInt(dgv.CurrentCell.Value.ToString) >= Fromdata AndAlso CInt(dgv.CurrentCell.Value.ToString) <= Todata Then
  100.                         dgv(2, dgv.CurrentCell.RowIndex).Value = Grade
  101.                         dgv(3, dgv.CurrentCell.RowIndex).Value = Points
  102.                                             End If
  103.                 End If
  104.             Next
  105.         End if
  106.         Catch ex As Exception
  107.             MsgBox("Error " & ex.Message , MsgBoxStyle.Critical)
  108.         End Try    
  109.     End Sub
  110. End Class
  111.  
Dec 20 '19 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: DraguVaso | last post by:
Hi, I'm using the DataGridView in VB.NET 2.0. The DataSource is a Generic List of a custom class0: lstMyPersonnes = New List(Of clsPersonne). When I add a new clsPersonne to lstMyPersonnes,...
10
by: Henok Girma | last post by:
Hello Gurus, I want to save the state of an unbound DataGridView on my Windows Form application to an XML file so i can later load it back.. Basically, on my form I have a DataGridView, it's got...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
2
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
7
by: Mitchell S. Honnert | last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the DataGridView? If not, is there an easy way to duplicate the DataGridTableStyle's functionality for the DataGridView? Here's...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: jeastman - Hotmail | last post by:
Hello world Excuse, not to be written English and it helps me with a translator. I am new programming in C#. I made a control inheriting the DataGridView to be able to add controls done by...
3
by: Andrus | last post by:
I have DataGridView in virtual mode containing 3500 rows. In code below, assigning to RowCount value to 3500 takes 8 seconds. CPU usage goes high at this time. Stepping by F11 into user code shows...
0
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
2
BRawn
by: BRawn | last post by:
Hi guys, I'm struggling to copy rows from one DataGridView to another. This may sound redundant but it's necessary for my Orders project. I have 3 DataGridViews on one form. The first...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.