VB.NET datagrid problem

D

Dennis T. Holm

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
 
G

Guest

I think the culprit here is: resultatGrid.TableStyles.Clear()

Please comment this line and try again.

Let me know the results.

cheers!
 

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