Mar 30th, 2010, 12:49 PM
#1
Thread Starter
New Member
DataGridView - Add Text To Cell
Hi,
I want to add text to a specific row, column in a DataGridView grid. I have tried several ways to do this bit none seem to work.
Is there a way to do this?
Thanks.
Mar 30th, 2010, 03:28 PM
#2
Hyperactive Member
Re: DataGridView - Add Text To Cell
Use:
Code:
datagridview.rows(rownumber).cells(columnnumber).value = text string
or
datagridview.rows(rownumber).cells("column name").value = text string
Computerman
It was much easier in VB6, but I am now liking Vb.Net alot more.
Mar 30th, 2010, 09:03 PM
#3
Re: DataGridView - Add Text To Cell
Originally Posted by
computerman
Use:
Code:
datagridview.rows(rownumber).cells(columnnumber).value = text string
or
datagridview.rows(rownumber).cells("column name").value = text string
Computerman
It's a bit more succinct to index the grid directly:
vb.net Code:
myGrid(columnIndex, rowIndex).Value = someValue
I'd only go via the row if I already had a reference to the row.
Mar 31st, 2010, 02:21 AM
#4
Thread Starter
New Member
Re: DataGridView - Add Text To Cell
Hi,
Thanks for your replies.
I tried the following but both ways don't seem to work:-
frmSearch.grdDB.Rows(2).Cells(1).Value = "Test"
frmSearch.grdDB(2, 1).Value = "Test"
I've attached a screenshot showing the error I get.
Thanks.
Attached Images
Mar 31st, 2010, 02:28 AM
#5
Re: DataGridView - Add Text To Cell
That's like someone teaching you how to drive and then you saying that it doesn't work if you drive into a wall. Both ways DO work and they are both working, otherwise you wouldn't be getting that error message. In order to get that error message the cell value has to be being set. The problem is that you're setting it to an invalid value. You can't assign the string "Test" to a cell that expects a number, which is what the error message is telling you.
Mar 31st, 2010, 03:20 AM
#6
Thread Starter
New Member
Re: DataGridView - Add Text To Cell
G'day jmcilhinney,
You're right! I've just tried it again and it works.
I'm converting from VB5 to VB.net so it does feel like driving into a wall a times.
Thanks for you response.
Mar 31st, 2010, 04:25 AM
#7
Re: DataGridView - Add Text To Cell
Fasten your seat belt and keep your hands inside the vehicle at all times!
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width