Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,080 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,786 people online right now. Registration is fast and FREE... Join Now!




Moving Textbox inputs to Data Grid View

 
Reply to this topicStart new topic

Moving Textbox inputs to Data Grid View

gram999
22 Apr, 2008 - 12:12 PM
Post #1

D.I.C Head
**

Joined: 21 Jan, 2008
Posts: 81



Thanked: 2 times
My Contributions
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.


Attached File(s)
Attached File  Calc.zip ( 38.43k ) Number of downloads: 64
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Moving Textbox Inputs To Data Grid View
22 Apr, 2008 - 01:26 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
I believe this is what you are looking for.

CODE

        Dim nr(4) As String 'change to string data type
        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

        dt.Rows.Add(nr) 'add string array to DataGridView


User is offlineProfile CardPM
+Quote Post

gram999
RE: Moving Textbox Inputs To Data Grid View
22 Apr, 2008 - 07:32 PM
Post #3

D.I.C Head
**

Joined: 21 Jan, 2008
Posts: 81



Thanked: 2 times
My Contributions
Thanks for the suggestion JayMan . I will give it a shot.
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Moving Textbox Inputs To Data Grid View
22 Apr, 2008 - 07:55 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,319



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Something I just noticed. You can take out the numeric conversion for those textboxes. It should be noted that you never assign a value to iPPR before you use it, just thought I would mention that.

CODE

        nr(0) = txtArea.Text
        nr(1) = txtPossPoints.Text
        nr(2) = txtPtsCited.Text
        nr(3) = txtTotalPts.Text
        nr(4) = iPPR.ToString()


As for the second part of your question, yes you can perform calculations and then put the results in the DataGridView in a Row. For example, if you were totaling a column, you could sum the column and then add a new row at the bottom which gives the results of those calculations.

What type of calculations did you have in mind?
User is offlineProfile CardPM
+Quote Post

gram999
RE: Moving Textbox Inputs To Data Grid View
23 Apr, 2008 - 04:50 AM
Post #5

D.I.C Head
**

Joined: 21 Jan, 2008
Posts: 81



Thanked: 2 times
My Contributions
Thanks JayMan! The calculations are very simple just addition and subtraction. You are take the PtsCited and subtract them from the Poss Points and you get either a positive or a negative total for Total Points. Thanks again for the pointers!
User is offlineProfile CardPM
+Quote Post

lionheart11
RE: Moving Textbox Inputs To Data Grid View
4 Aug, 2008 - 05:31 AM
Post #6

New D.I.C Head
*

Joined: 4 Aug, 2008
Posts: 1

sir thanks for the code
but can you help me more plz
if you load image for the form and named the components to understand more
or if you can send the project
thanks again
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:31PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month