473,664 Members | 3,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inputes in datagridview

1 New Member
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(subject s,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 3077
SioSio
272 Contributor
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
3602
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, and rebind the lstMyPersonnes to my DataGridView.dataSource, it shows the new record in the DataGridView as it should be. But when I click on a cell of that row, I suddenly got this error: "Index -1
10
39481
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 some DataGridViewTextBoxCell, DataGridViewComboBoxCell etc, i want to export all that to XML.. Any help is greatly appreciated.
3
32261
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 datatable without having to loop through each column in the datagridview? Or is there a way to retrieve the rows from the original datatable filtered by the dataview into a separate table? I only want to copy the rows from the main table that...
2
24534
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 you update after closing the grid/form, etc.? Also, can you tell me the best book to buy that fully explains the DataGridView control? Thanks.
7
12599
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 the background for my question... Before I switched my application over to the Fx 2.0, I used a DataGrid to display my data. I would store different DataGridTableStyles (each one with a custom set of columns) in the DataGrid.TableStyles property...
7
15648
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 there an equivalent property for the DataGridView? I have searched, but have not found one. I would like the user to be able to see all the columns of the table on one screen - thus eliminating the need to use the horizontal scroll bar to view...
0
2498
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 my.
3
5732
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 few celltemplate property getters and combobox/datecombo constructor calls without database access which does not take a lot of time. Debug output (below) shows lot of messages Stepping over non-user code. Running in release mode from...
0
5646
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 blank unless they are filled by the user. 2) As soon as the user enters a cell, the dtp control should appear as the editing control of that cell. If there's a value in the cell beforehand, that value is set as the value of the dtp editing control...
2
13950
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 DataGridView gets populated from my database with the product and total available stock. The second DataGridView is sort of a basket...so, when an item is selected from the first DataGridView, the item gets added to the second DataGridView and there's an...
0
8348
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8861
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8549
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7375
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4185
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4351
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.