Setting the length of datagrid columns

B

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()
 
J

Jorge

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 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'
 
B

Bob Avallone

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top