By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,278 Members | 1,086 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,278 IT Pros & Developers. It's quick & easy.

Setting the length of datagrid columns

P: n/a
bob
I am binding a datatable to a datagrid in VB.NET I then want to change
the width of the first column. I am unable to get the right syntax.

Here is the code I tried
Dim mydataset As DataSet

gclodatabase.GetDataSetJobs("Select * from qryJobs",
mydataset)
Dim Mydatatable As DataTable = mydataset.Tables(0)
dtgSelect.DataSource = mydataset.Tables(0)

dtgSelect.TableStyles(0).GridColumnStyles("JobId") .Width = 10

‘ this fails with an error An unhandled exception of type
'System.NullReferenceException' occurred in Proposals.exe

‘Additional information: Object reference not set to an instance of an
‘object.
dtgSelect.TableStyles(0).GridColumnStyles(1).Width = 10

‘ this fails with error

‘An unhandled exception of type 'System.ArgumentOutOfRangeException'
‘occurred in mscorlib.dll

‘Additional information: Index was out of range. Must be non-negative
‘and less than the size of the collection.
dtgSelect.Refresh()
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi
You need to add the TableStyle "JobID" to the datagrid
before you can use it.
Kind Regards
Jorge
-----Original Message-----
I am binding a datatable to a datagrid in VB.NET I then want to changethe width of the first column. I am unable to get the right syntax.
Here is the code I tried
Dim mydataset As DataSet

gclodatabase.GetDataSetJobs("Select * from qryJobs",mydataset)
Dim Mydatatable As DataTable = mydataset.Tables (0)

dtgSelect.DataSource = mydataset.Tables(0)

dtgSelect.TableStyles(0).GridColumnStyles ("JobId").Width = 10
' this fails with an error An unhandled exception of type
'System.NullReferenceException' occurred in Proposals.exe

'Additional information: Object reference not set to an instance of an'object.
dtgSelect.TableStyles(0).GridColumnStyles (1).Width = 10
' this fails with error

'An unhandled exception of type 'System.ArgumentOutOfRangeException''occurred in mscorlib.dll

'Additional information: Index was out of range. Must be non-negative'and less than the size of the collection.
dtgSelect.Refresh()
.

Nov 20 '05 #2

P: n/a
>>
Hi
You need to add the TableStyle "JobID" to the datagrid
before you can use it.
Kind Regards
Jorge


Can you show me what the line of code is to do that?

Thanks,

Bob Avallone
www.metaprosystems.com


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.