Computing.Net > Forums > Programming > vb.net DataGridView question

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

vb.net DataGridView question

Reply to Message Icon

Original Message
Name: byrnesit
Date: April 9, 2007 at 18:01:55 Pacific
Subject: vb.net DataGridView question
OS: Windows XP Pro SP2
CPU/Ram: PM1.7 1024mb
Model/Manufacturer: Dell
Comment:

Hi guys,
I'm just starting to covert over to VB.NET2005 (had been in the dark ages using VB6 until now), and although it is strange to me in a few ways I am getting used to it and liking .net more and more...

One problem I am having though, is I am using and unbound DataGridView that I am setting up in-code rather than through the gui, which is all fine and working great, but I am having problems when creating new rows. I have figured out how to do this in two ways,

Firstly I can go
dgv.Rows.Add()
dvb..Rows(dgv.Rows.Count()).Cells("blah").Value = "blah!"

Secondly (and the way I want to do it) I can go

Dim dgvr As New DataGridViewRow
dgvr.CreateCells(dgv)
dgvr.Cells(0).Value = "Blah"
dgvr.Cells(1).Value = "Blah Blah"
dgv.rows.add(dgvr)

My problem/question is, I currently have to refer to the cells by number (ie: dgvr.cells(0).va...), but I would much prefer to refer to them by name like I do when i add teh row then mess with it as in the first example - I find using the names will lead to less confusion and neater, more self-documenting code... But why doesnt it work?

When I try to do this, and run the app, i get an 'ArgumentExeption was unhandled'...'Column name Blah could not be found' error (and yes, i have checked that i am using the correct name for the cell).

Is it that when the row gets created it doesnt create the cells with the same names as the columns?... I dunno...

If anyone out there knows how to do this please let me know

Thanks in advance and i appologise for the long post


Report Offensive Message For Removal


Response Number 1
Name: SN
Date: April 10, 2007 at 23:24:00 Pacific
Reply: (edit)

Note that the column names are case sensitive, even though VB isn't. In the example that works, you say "blah", and in the error message, you refer to "Blah."

Good luck,
SN


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software