Results 1 to 12 of 12

Thread: VB2005 Save coordinates in array?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    VB2005 Save coordinates in array?

    Hello,

    I have a form called frmMainForm. On that form I have a datagridview containing several products.
    When I click on a rowheader of the datagridview another form openes called frmCuts.
    On the frmCuts you can add coordinates for a product.
    For example (2, 2, 67, 103).

    How can I assign these coordinates to the row in the datagridview?
    I am not allowed to save the coordinates in the database.

    How do I save them for the duration that the program is open?

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: VB2005 Save coordinates in array?

    or inside an arraylist
    "The dark side clouds everything. Impossible to see the future is."

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: VB2005 Save coordinates in array?

    Quote Originally Posted by Asgorath
    or inside an arraylist
    Could you please give me a little example please?

  4. #4
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: VB2005 Save coordinates in array?

    Just call the .Add(value) method
    "The dark side clouds everything. Impossible to see the future is."

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: VB2005 Save coordinates in array?

    I do not understand...sorry

  6. #6
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: VB2005 Save coordinates in array?

    VB Code:
    1. Dim arr as new ArrayList
    2. arr.Add(2)
    3. arr.Add(2)
    4. arr.Add(67)
    5. arr.Add(103)
    "The dark side clouds everything. Impossible to see the future is."

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: VB2005 Save coordinates in array?

    But my arry will have to look lik

    ProductID Coordinates
    2 (1, 3, 66, 77)
    5 (44, 66, 89, 8)

    And so on

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB2005 Save coordinates in array?

    Define a class for your product. Create a BindingList and add instances of your class to it. Bind that list to your grid. When you open the dialogue pass one of the class instances to it. When you make changes to the object in the dialogue they will be reflected in the grid because the same object is still bound to the grid.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: VB2005 Save coordinates in array?

    Thank you very much for the reply.

    Could youplease provide me with an example.
    Because I dont get it..

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: VB2005 Save coordinates in array?

    Read my post one sentence at a time.
    Define a class for your product.
    Do you know how to define a class? What members would your class need?
    Create a BindingList and add instances of your class to it.
    Have you used a BindingList before? Probably not, but it is just a collection with some special behaviour that makes it good for data binding. Look it up on MSDN and read about it.
    Bind that list to your grid.
    You already know how to bind to a grid because you've done it before with a DataTable I'll wager. Etc., etc. Just because you haven't done that whole thing before doesn't mean you can't do parts of it. Someone may not be able to drive but that doesn't mena someone has to show them how to turn an ignition key. I believe that you are capable of implementing at least part of what I have suggested. The fact that you posted three minutes after me indicates that you didn't ponder the possibility too long.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: VB2005 Save coordinates in array?

    Yes I know what a class is but not how to use it in my case.

    I read about the bindinglist but I just dont get it.

    And I know how to bind data.

    I just dont see it.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Netherlands
    Posts
    817

    Re: VB2005 Save coordinates in array?

    Can I reach my purpose using a collection?

    I tried this:

    VB Code:
    1. Dim intNumberOfRows As Integer
    2. Dim intRow As Integer = 0
    3. Dim colData As New Collection
    4. Dim coordinates As String
    5.  
    6. Private Sub frmMainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7.  
    8. intNumberOfRows = WoodsheetsTableAdapter.Fill(Me.WoodshopDataSet.woodsheets)
    9. Dim row As DataRow = Nothing
    10. Dim i As Integer
    11.  
    12. For i = 0 To intNumberOfRows
    13. row = WoodshopDataSet.woodsheets.Rows(0)
    14. colData.Add(coordinates, row.Item(1))
    15. Next i

    But I get an error message saying something about "dublicate keys.."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width