I am completely stuck on this. It is the first time that I have used data grid view and I am trying to get data that is entered in textboxes to show up in columns/rows in dataview replicating the functionality of the attached Excel spreadsheet. My code to date is listed below. I am stuck because I am not sure how to get data into the data grid if you are not using a database (or if that is even possible) also I am not sure if you can calculate an item and have it appear in the data grid. Here is what I have been able to cobble together from examples I have found on the Internet. I have to warn that this may be completely off base as I have been attempting to cobble something together by looking at examples and Internet sites.
CODE
Imports System.IO
Public Class Form1
Public Structure AppealsCalculator
Private mArea As String
Private mPPoints As Integer
Private mPCited As Integer
Private mTPoints As Integer
Private mPPTReturn As Integer
Public Sub New(ByVal Area As String, ByVal PPoints As Integer, ByVal PCited As Integer, ByVal TPoints As Integer, ByVal PPTReturn As Integer)
mArea = Area
mPPoints = PPoints
mPCited = PCited
mTPoints = TPoints
mPPTReturn = PPTReturn
End Sub
Public Property Area() As String
Get
Return mArea
End Get
Set(ByVal value As String)
mArea = value
End Set
End Property
Public Property PPoints() As Integer
Get
Return mPPoints
End Get
Set(ByVal value As Integer)
mPPoints = value
End Set
End Property
Public Property PCited() As Integer
Get
Return mPCited
End Get
Set(ByVal value As Integer)
mPCited = value
End Set
End Property
Public Property TPoints() As Integer
Get
Return mTPoints
End Get
Set(ByVal value As Integer)
mTPoints = value
End Set
End Property
Public Property PPTReturn() As Integer
Get
Return mPPTReturn
End Get
Set(ByVal value As Integer)
mPPTReturn = value
End Set
End Property
Public Overrides Function ToString() As String
Return mArea & "_" & mPPoints & "_" & mPCited & "_" & mTPoints & "_" & mPPTReturn.ToString
End Function
End Structure
Dim ds As New DataSet
Dim dt As New DataTable("AppealOutput")
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InitTable()
ds.Tables.Add(dt)
End Sub
Private Sub InitTable()
Dim col1 As New DataColumn("Area", GetType(System.String))
Dim col2 As New DataColumn("Possible Points for Area", GetType(System.Int32))
Dim col3 As New DataColumn("Points Cited", GetType(System.Int32))
Dim col4 As New DataColumn("Points Appealable", GetType(System.Int32))
Dim col5 As New DataColumn("Possible Points Returned", GetType(System.Int32))
End Sub
Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click
Dim nr As DataRow = dt.NewRow
Dim strNote As String
Dim strYNBx As String
Dim iPP, iPC, iPA, iPPR As Int32
nr(0) = txtArea.Text
nr(1) = CInt(txtPossPoints.Text)
nr(2) = CInt(txtPtsCited.Text)
nr(3) = CInt(txtTotalPts.Text)
nr(4) = iPPR
iPP = CInt(txtPossPoints.Text)
iPC = CInt(txtPtsCited.Text)
iPA = CInt(txtTotalPts.Text)
If iPC > iPP Then iPPR = ((iPP - iPC) + iPA)
If iPC <= iPP Then iPPR = iPA
strNote = "Do you have another item to add?"
strYNBx = MessageBox.Show(strNote, "My Application", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If strYNBx = DialogResult.Yes Then
txtArea.Text = String.Empty
txtPossPoints.Text = String.Empty
txtPtsCited.Text = String.Empty
txtTotalPts.Text = String.Empty
txtArea.Focus()
Else
Dim sfd As New SaveFileDialog
With sfd
.InitialDirectory = "c:\"
.Filter = "All Files |*.*"
.ShowDialog()
End With
End If
End Sub
End Class
Nothing for code in Form2 yet where the data grid is. I did put in a Class though to pass data between the 2 forms. Here is that code:
CODE
Public Class FormLibrary
Public Shared Form1 As Form
Public Shadows Form2 As Form
End Class
To see exactly what I am trying to accomplish take a look at the attached Excel file. When the first form comes up click the "No thanks,..." button. I am trying to recreate this exactly using VB.Net. Thanks in advance for any suggestions/guidance.