Results 1 to 10 of 10

Thread: [02/03] Datagrid

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Post [02/03] Datagrid

    Hi,

    I have a structure decalared with a set of fields and I need to populate this in a dataGrid. All the examples I have seen use database connections. Can anyone tell me how I can populate the grid usig my structure?

    Thanks

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: [02/03] Datagrid

    Lets assume that you have a structure that has 2 properties
    .
    You need to create 2 public properties (p.e. name, id)
    You need a sub new
    p.e. Public Sub New(ByVal name As String, ByVal id As Integer)
    Ok structure complete.

    Now you will add the elements to the datagrid, so
    Code:
     Private Sub addTogrid()
            Dim myDivisions As New ArrayList
            With myDivisions
                .Add(New StructureGeneralComboHelper("ΙJo", 1))
                .Add(New StructureGeneralComboHelper("GO", 2))
                .Add(New StructureGeneralComboHelper("Test", 3))
                .Add(New StructureGeneralComboHelper("One", 4))
            End With
            Me.DataGridView1.SuspendLayout()
            With Me.DataGridView1
                .DataSource = myDivisions
            End With
            Me.DataGridView1.ResumeLayout()
        End Sub
    Thats it.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [02/03] Datagrid

    Thanks,

    My grid is just populating 1 column and its all fixed. so no data. Can you expand a little more? My structure is below if it helps.


    Public Structure ClientProductsList
    Dim invoiceCode As String
    Dim productCode As String
    Dim productDescription As String
    Dim productQuantity As Long
    Dim ProductPrice As Long
    Dim ProductNetValue As Long
    end Structure

  4. #4
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: [02/03] Datagrid

    Yes you need 6 public properties and 6 Private declarations
    Public ReadOnly Property IinvoiceCode () As String
    Get
    Return strinvoice
    End Get
    End Property
    Private strinvoice as string
    Also in sub new you need 6 objects
    Public Sub New(ByVal invoiceCode As String, ByVal productCode As string ...etc)

    when you add the item you do:
    .Add(New StructureGeneralComboHelper("ΙJo", "1","df","sdf","dg","fh"))
    the 6 items.
    The other parts are the same.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [02/03] Datagrid

    Ok I'm still a Vb6 developer trying to transist to .Net been at itfor a few months now. Can I ask am I creating a class now ora structure? How am I decalring the structure (use your example of 2 properties)

    Thanks Again

  6. #6
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: [02/03] Datagrid

    Yes it's like a class isn't it?
    No you do it with a structure (you could do it in a class also).
    You have declared it ok.
    Now change all the dim to Private
    Add 6 public properties
    The part you may missing is this...
    Public Sub New(ByVal name As String, ByVal id As Integer)
    divName = name
    divID = id
    End Sub
    you must provide all the 6 strings a value for the Private variables.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [02/03] Datagrid

    Sorry couldnt grasp the concept of having routines within the structure... Hmm vb6 shining through.

    Thanks.

  8. #8
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: [RESOLVED] [02/03] Datagrid

    No problem.C.U.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [RESOLVED] [02/03] Datagrid

    When you double clik the columns on the data grid it sets them to the size of the largest text, is there a programatic way to do this?

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [02/03] Datagrid

    Also can you stop the user from editing the cells? (but still allow them to clikc a row)

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