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

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

vb.net DataGridView question

Reply to Message Icon

Name: byrnesit
Date: April 9, 2007 at 18:01:55 Pacific
OS: Windows XP Pro SP2
CPU/Ram: PM1.7 1024mb
Product: 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



Sponsored Link
Ads by Google

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

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


0
Reply to Message Icon

Related Posts

See More







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


Sponsored links

Ads by Google


Results for: vb.net DataGridView question

VB.NET picture question www.computing.net/answers/programming/vbnet-picture-question/13841.html

Questions vb.net www.computing.net/answers/programming/questions-vbnet/12968.html

VB.NET Image Path Questions www.computing.net/answers/programming/vbnet-image-path-questions/17618.html