Solved

help using dataviewgrid for selected items on form

Posted on 2010-09-22
8
248 Views
Last Modified: 2012-05-10
Hi,
   I am creating an EPOS system and I have a series of buttons on my form.  When someone clicks a button I want the following to be added under columns on the dataviewgrid1 component:

Description
Quantity
Price
Vat

Then when another button is clicked, on another line the new item etc

How can I do this?

Thanks
0
Comment
Question by:damianb123
  • 5
  • 3
8 Comments
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
Hi.
You mean DatagridView?
0
 

Author Comment

by:damianb123
Comment Utility
Yup - sorry!!!
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
try this in form LoadEvent...(if i understand well)
 Dim txt1, txt2, txt3, txt4 As New DataGridViewTextBoxColumn

        txt1.Name = "Description"

        txt2.Name = "Quantity"

        txt3.Name = "Price"

        txt4.Name = "Vat"



        Me.DataGridView1.Columns.Insert(0, txt1)

        Me.DataGridView1.Columns.Insert(1, txt2)

        Me.DataGridView1.Columns.Insert(2, txt3)

        Me.DataGridView1.Columns.Insert(3, txt4)

Open in new window

0
 

Author Comment

by:damianb123
Comment Utility
jtoutou,
    that works great, thanks.  Now what i need to do is have the system so that when a button is clicked the details are added to the form.....  This is the code I used on a previous project, however the description was only piped to a txt box and not multiple columns.  
Multiple buttons need to be capable of adding multiple rows.....

Thanks
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
Sorry for the delay .....ok we have the column ....now for the cells....
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim dgvRow As New DataGridViewRow

        Dim dgvCell As DataGridViewCell



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomeDescription"

        dgvRow.Cells.Add(dgvCell)



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomeQuantity"

        dgvRow.Cells.Add(dgvCell)



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomePrice"

        dgvRow.Cells.Add(dgvCell)



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomeVat"

        dgvRow.Cells.Add(dgvCell)



        DataGridView1.Rows.Add(dgvRow)



    End Sub

Open in new window

0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
Comment Utility
And just a note:Rows cannot be added programatically to the datagridview's collection when control is databound!!!!!we are talking now about custom Datagridview.....


in this case lets say we have to buttons....just do the same job with defferent text...
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim dgvRow As New DataGridViewRow

        Dim dgvCell As DataGridViewCell



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomeDescription"

        dgvRow.Cells.Add(dgvCell)



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomeQuantity"

        dgvRow.Cells.Add(dgvCell)



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomePrice"

        dgvRow.Cells.Add(dgvCell)



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomeVat"

        dgvRow.Cells.Add(dgvCell)



      

        Me.DataGridView1.Rows.Add(dgvRow)



    End Sub



    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim dgvRow As New DataGridViewRow

        Dim dgvCell As DataGridViewCell



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomeDescription2"

        dgvRow.Cells.Add(dgvCell)



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomeQuantity2"

        dgvRow.Cells.Add(dgvCell)



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomePrice2"

        dgvRow.Cells.Add(dgvCell)



        dgvCell = New DataGridViewTextBoxCell()

        dgvCell.Value = "SomeVat2"

        dgvRow.Cells.Add(dgvCell)





        Me.DataGridView1.Rows.Add(dgvRow)

    End Sub

Open in new window

0
 

Author Closing Comment

by:damianb123
Comment Utility
This worked perfectly, thanks very much for all your help!
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
Comment Utility
very welcome.....very glad helping you
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now