|
-
Oct 7th, 2009, 04:36 AM
#1
Thread Starter
Member
[RESOLVED] How to add more 2 columns to DataGrid ?
DataGrid came by default with two columns only (0, 1)
So, how can I add more than 2 columns to a DataGrid ?
-
Oct 7th, 2009, 05:04 AM
#2
-
Oct 7th, 2009, 05:50 AM
#3
Thread Starter
Member
Re: How to add more 2 columns to DataGrid ?
 Originally Posted by jp26198926
DataGrid1.Columns.Add 2
I used it like the following code:
VB Code:
DataGrid1.Columns.Add 5
DataGrid1.Columns(0).Caption = "111"
DataGrid1.Columns(1).Caption = "222"
DataGrid1.Columns(2).Caption = "333"
DataGrid1.Columns(3).Caption = "444"
DataGrid1.Columns(4).Caption = "555"
I got this error messege:
Runtime error '424':
Object required
Last edited by alMubarmij; Oct 7th, 2009 at 06:24 AM.
-
Oct 7th, 2009, 06:00 AM
#4
Re: How to add more 2 columns to DataGrid ?
try like this
Code:
For i = 0 To 4
DataGrid1.Columns.Add(i).Caption = "Column " & i
Next
-
Oct 7th, 2009, 06:15 AM
#5
Hyperactive Member
Re: How to add more 2 columns to DataGrid ?
DataGrid.Columns(0).....
should be..
DataGrid1.Columns(0)....
Code:
Dim i As Integer
For i = 2 To 4
DataGrid1.Columns.Add i
Next i
DataGrid1.Columns(0).Caption = "111"
DataGrid1.Columns(1).Caption = "222"
DataGrid1.Columns(2).Caption = "333"
DataGrid1.Columns(3).Caption = "444"
DataGrid1.Columns(4).Caption = "555"
"More Heads are Better than One"
-
Oct 7th, 2009, 06:24 AM
#6
Thread Starter
Member
Re: How to add more 2 columns to DataGrid ?
This code will work correctly:
VB Code:
DataGrid1.ColumnHeaders = True
For i = 0 To 4
DataGrid1.Columns.Add(i)
Next
DataGrid1.Columns(0).Caption = "Header-1"
DataGrid1.Columns(1).Caption = "Header-2"
DataGrid1.Columns(2).Caption = "Header-3"
DataGrid1.Columns(3).Caption = "Header-4"
DataGrid1.Columns(4).Caption = "Header-5"
I was use "DataGrid" not "DataGrid1".
Thanks for all.
Last edited by alMubarmij; Oct 7th, 2009 at 06:31 AM.
-
Oct 7th, 2009, 06:34 AM
#7
Thread Starter
Member
Re: How to add more 2 columns to DataGrid ?
The main problem now that "DataField" property does not work:
VB Code:
DataGrid1.Columns(0).DataField = "Field1"
DataGrid1.Columns(1).DataField = "Field2"
DataGrid1.Columns(2).DataField = "Field3"
DataGrid1.Columns(3).DataField = "Field4"
DataGrid1.Columns(4).DataField = "Field5"
I got now all columns in my query not only that five !
Can I customize the number of columns in design mode (not in runtime) ?
-
Oct 7th, 2009, 06:41 AM
#8
Re: How to add more 2 columns to DataGrid ?
u can add columns in design time aslo, right click -> edit, again right click -> insert
-
Oct 7th, 2009, 06:59 AM
#9
Thread Starter
Member
Re: How to add more 2 columns to DataGrid ?
Tags for this Thread
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
|