473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

Nov 21 '05 #1
2 1352
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
-----------------------
"Dennis T. Holm" <de****@contempt.dk> wrote in message
news:43***********************@news.sunsite.dk...
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


Nov 21 '05 #2
I think the culprit here is: resultatGrid.TableStyles.Clear()

Please comment this line and try again.

Let me know the results.

cheers!

"Dennis T. Holm" wrote:
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

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell...
0
by: Emerson | last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C# Here's my scenario I click in a cell on a DataGrid. I enter some...
5
by: Jeff | last post by:
IDE: VS 2003 :NET OS: XP Pro My app have a form with a tab-control on it. The tab-control have 2 tabpages. One of the tabpages displays a datagrid, and the other tabpage displays details (order...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
9
by: tshad | last post by:
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled? I have a bunch of DataGrids that get displayed nested inside a DataList. The datagrid looks like: ...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
0
by: optimizeit | last post by:
What I am attempting to do is import an Excel Workbook and display the worksheets in a datagrid dynamically. I am very close to getting this to work. I have to this point successfully imported a...
9
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.