Setting the length of datagrid columns

  • Thread starter Thread starter bob
  • Start date Start date
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()
 
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'
 
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
 
Back
Top