Im having problems with setting the width of my columns of my datagrid.
Here's the code
resultatGrid.DataSource = getFirms(0) // gets metaData from database
Dim tableStyle As New DataGridTableStyle
tableStyle.PreferredColumnWidth = 100
tableStyle.RowHeadersVisible = False
tableStyle.MappingName = "firmaer"
resultatGrid.TableStyles.Clear()
resultatGrid.TableStyles.Add(tableStyle)
Dim colStyle As GridColumnStylesCollection =
resultatGrid.TableStyles(0).GridColumnStyles
colStyle.Item("FirmaID").Width = 0
colStyle.Item("Firma Navn").Width = 200
colStyle.Item("Adresse").Width = 100
colStyle.Item("Post nr").Width = 100
colStyle.Item("By").Width = 150
colStyle.Item("CVR nr").Width = 150
I get an exception when using the colStyle.Item() commands ... it should
work but it doesnt --
I get the following exceptoin: System.NullReferenceException
Object reference not set to an instance of an object ..
MVH
Dennis Holm
dennis t holm
sponsored links
2
29th October 07:01
patrick sullivan
External User
Posts: 1
VB.Net datagrid problem
Not sure if this is it, but if your mappingnames don't match actual table
and column names, the datagrid will not use them. So the values will be
nulls. hth
--
Patrick Sullivan, AA-BA, BA-IT
patrick sullivan
3
29th October 07:19
dennis t holm
External User
Posts: 1
VB.Net datagrid problem
You are right ... it was my mapping name ... logically it has to be the
same so now its working ...
THANKS
dennis t holm
4
29th October 07:35
patrick sullivan
External User
Posts: 1
VB.Net datagrid problem
You welcome. Wish I could help people half as much as I've gotten it.
--
Patrick Sullivan, AA-BA, BA-IT
patrick sullivan
5
26th February 06:43
dennis t. holm
External User
Posts: 1
VB.NET datagrid problem
HEy
Im having problems with setting the width of my columns of my datagrid.
Here's the code
resultatGrid.DataSource = getFirms(0) // gets metaData from database
Dim tableStyle As New DataGridTableStyle
tableStyle.PreferredColumnWidth = 100
tableStyle.RowHeadersVisible = False
tableStyle.MappingName = "firmaer"
resultatGrid.TableStyles.Clear()
resultatGrid.TableStyles.Add(tableStyle)
Dim colStyle As GridColumnStylesCollection =
resultatGrid.TableStyles(0).GridColumnStyles
colStyle.Item("FirmaID").Width = 0
colStyle.Item("Firma Navn").Width = 200
colStyle.Item("Adresse").Width = 100
colStyle.Item("Post nr").Width = 100
colStyle.Item("By").Width = 150
colStyle.Item("CVR nr").Width = 150
I get an exception when using the colStyle.Item() commands ... it should
work but it doesnt --
I get the following exceptoin: System.NullReferenceException
Object reference not set to an instance of an object ..
MVH
Dennis Holm
dennis t. holm
6
27th February 03:49
ken tucker [mvp]
External User
Posts: 1
VB.NET datagrid problem
Hi,
Are you sure you spelled all the column names right? You will
get the error if the item is not in the collection.
Ken
-----------------------
HEy
Im having problems with setting the width of my columns of my datagrid.
Here's the code
resultatGrid.DataSource = getFirms(0) // gets metaData from database
Dim tableStyle As New DataGridTableStyle
tableStyle.PreferredColumnWidth = 100
tableStyle.RowHeadersVisible = False
tableStyle.MappingName = "firmaer"
resultatGrid.TableStyles.Clear()
resultatGrid.TableStyles.Add(tableStyle)
Dim colStyle As GridColumnStylesCollection =
resultatGrid.TableStyles(0).GridColumnStyles
colStyle.Item("FirmaID").Width = 0
colStyle.Item("Firma Navn").Width = 200
colStyle.Item("Adresse").Width = 100
colStyle.Item("Post nr").Width = 100
colStyle.Item("By").Width = 150
colStyle.Item("CVR nr").Width = 150
I get an exception when using the colStyle.Item() commands ... it should
work but it doesnt --
I get the following exceptoin: System.NullReferenceException
Object reference not set to an instance of an object ..
MVH
Dennis Holm
ken tucker [mvp]
7
10th April 14:54
calgarianø&¥ªâjwb±Ë¬²*²h®(~×(
External User
Posts: 1
VB.NET datagrid problem
I think the culprit here is: resultatGrid.TableStyles.Clear()
Please comment this line and try again.
Let me know the results.
cheers!
calgarianø&¥ªâjwb±Ë¬²*²h®(~×(
8
10th April 13:20
dennis t. holm
External User
Posts: 1
VB.NET datagrid problem
HEy
Im having problems with setting the width of my columns of my datagrid.
Here's the code
resultatGrid.DataSource = getFirms(0) // gets metaData from database
Dim tableStyle As New DataGridTableStyle
tableStyle.PreferredColumnWidth = 100
tableStyle.RowHeadersVisible = False
tableStyle.MappingName = "firmaer"
resultatGrid.TableStyles.Clear()
resultatGrid.TableStyles.Add(tableStyle)
Dim colStyle As GridColumnStylesCollection =
resultatGrid.TableStyles(0).GridColumnStyles
colStyle.Item("FirmaID").Width = 0
colStyle.Item("Firma Navn").Width = 200
colStyle.Item("Adresse").Width = 100
colStyle.Item("Post nr").Width = 100
colStyle.Item("By").Width = 150
colStyle.Item("CVR nr").Width = 150
I get an exception when using the colStyle.Item() commands ... it should
work but it doesnt --
I get the following exceptoin: System.NullReferenceException
Object reference not set to an instance of an object ..
MVH
Dennis Holm
dennis t. holm
9
20th April 07:59
ken tucker [mvp]
External User
Posts: 1
VB.NET datagrid problem
Hi,
Are you sure you spelled all the column names right? You will
get the error if the item is not in the collection.
Ken
-----------------------
HEy
Im having problems with setting the width of my columns of my datagrid.
Here's the code
resultatGrid.DataSource = getFirms(0) // gets metaData from database
Dim tableStyle As New DataGridTableStyle
tableStyle.PreferredColumnWidth = 100
tableStyle.RowHeadersVisible = False
tableStyle.MappingName = "firmaer"
resultatGrid.TableStyles.Clear()
resultatGrid.TableStyles.Add(tableStyle)
Dim colStyle As GridColumnStylesCollection =
resultatGrid.TableStyles(0).GridColumnStyles
colStyle.Item("FirmaID").Width = 0
colStyle.Item("Firma Navn").Width = 200
colStyle.Item("Adresse").Width = 100
colStyle.Item("Post nr").Width = 100
colStyle.Item("By").Width = 150
colStyle.Item("CVR nr").Width = 150
I get an exception when using the colStyle.Item() commands ... it should
work but it doesnt --
I get the following exceptoin: System.NullReferenceException
Object reference not set to an instance of an object ..