|
-
Jun 26th, 2007, 03:11 AM
#1
Thread Starter
PowerPoster
[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
-
Jun 26th, 2007, 03:28 AM
#2
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.
-
Jun 26th, 2007, 03:51 AM
#3
Thread Starter
PowerPoster
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
-
Jun 26th, 2007, 04:02 AM
#4
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.
-
Jun 26th, 2007, 04:11 AM
#5
Thread Starter
PowerPoster
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
-
Jun 26th, 2007, 04:17 AM
#6
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.
-
Jun 26th, 2007, 04:24 AM
#7
Thread Starter
PowerPoster
Re: [02/03] Datagrid
Sorry couldnt grasp the concept of having routines within the structure... Hmm vb6 shining through.
Thanks.
-
Jun 26th, 2007, 04:27 AM
#8
Re: [RESOLVED] [02/03] Datagrid
-
Jun 26th, 2007, 06:20 AM
#9
Thread Starter
PowerPoster
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?
-
Jun 26th, 2007, 08:16 AM
#10
Thread Starter
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|