473,325 Members | 2,774 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,325 software developers and data experts.

Setting Single Cell in DataGridView

My apologies upfront for what I am sure is a newbie question, but I
have been unable to find an answer via search.

I am a VB6 programmer trying to write programs in VB 2008 Express.

I have an 'unbound' datagrid control view on a form and just want to
be able to write text to individual cells.

I can programatically set the number of rows and cells, but have been
unable to select and/or write to cells.

Simple things that worked for the FlexGrid view in VB6 don't seem to
apply;

I can't just write (on a command button click event)
me.datgridview1.row= 1 ; me.datgridview1.col= 1 ;
me.datgridview1.text= "something"

These all seem to result in syntax errors.

How do I do a simple thing like this?

Thanks in advance
Jul 19 '08 #1
7 13427
A DataGrid is .NET is made up of collections of rows and columns. These
collections contain row and column objects respectively. In .NET, all
collections are zero-based.

So, if you wish to get to the second row of a DataGrid, you'd type:

dataGridName.Rows(1)

and if you wanted to get access to the third column (called items in a row
object), you'd type:

dataGridName.Rows(1).Item(2)

....and if you wanted to place a value in that column, you'd type:

dataGridName.Rows(1).Item(2) = "something"

One word of advice as you move to .NET from VB 6.0; understand the working
in VB .NET is not at all like working in VB 6.0, in terms of the objects
you'll use and the way the language is compiled. It is actually best to
discard your VB 6.0 knowledge (hard as that may be to accept) and start
fresh.

-Scott

"bobk" <in**@minuteman-systems.comwrote in message
news:01**********************************@f36g2000 hsa.googlegroups.com...
My apologies upfront for what I am sure is a newbie question, but I
have been unable to find an answer via search.

I am a VB6 programmer trying to write programs in VB 2008 Express.

I have an 'unbound' datagrid control view on a form and just want to
be able to write text to individual cells.

I can programatically set the number of rows and cells, but have been
unable to select and/or write to cells.

Simple things that worked for the FlexGrid view in VB6 don't seem to
apply;

I can't just write (on a command button click event)
me.datgridview1.row= 1 ; me.datgridview1.col= 1 ;
me.datgridview1.text= "something"

These all seem to result in syntax errors.

How do I do a simple thing like this?

Thanks in advance

Jul 19 '08 #2
On Jul 19, 4:42*pm, "Scott M." <s-...@nospam.nospamwrote:
A DataGrid is .NET is made up of collections of rows and columns. *These
collections contain row and column objects respectively. *In .NET, all
collections are zero-based.

So, if you wish to get to the second row of a DataGrid, you'd type:

dataGridName.Rows(1)

and if you wanted to get access to the third column (called items in a row
object), you'd type:

dataGridName.Rows(1).Item(2)

...and if you wanted to place a value in that column, you'd type:

dataGridName.Rows(1).Item(2) = "something"

One word of advice as you move to .NET from VB 6.0; understand the working
in VB .NET is not at all like working in VB 6.0, in terms of the objects
you'll use and the way the language is compiled. *It is actually best to
discard your VB 6.0 knowledge (hard as that may be to accept) and start
fresh.

-Scott

"bobk" <i...@minuteman-systems.comwrote in message

news:01**********************************@f36g2000 hsa.googlegroups.com...
My apologies upfront for what I am sure is a newbie question, but I
have been unable to find an answer via search.
I am a VB6 programmer trying to write programs in VB 2008 Express.
I have an 'unbound' datagrid control view on a form and just want to
be able to write text to individual cells.
I can programatically set the number of rows and cells, but have been
unable to select and/or write to cells.
Simple things that worked for the FlexGrid view in VB6 don't seem to
apply;
I can't just write (on a command button click event)
me.datgridview1.row= 1 ; me.datgridview1.col= 1 ;
me.datgridview1.text= "something"
These all seem to result in syntax errors.
How do I do a simple thing like this?
Thanks in advance- Hide quoted text -

- Show quoted text -
Thank you but that does not work.

It gives an error message that "item is not a member of
System.Windows.Forms.DataGridViewRow"

Here is the whole procedure;

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Me.DataGridView1.Rows(1).item(1) = "something"
End Sub

Is there some declaration or something I have to include to get it to
recognize the control/collection?

Bob
Jul 20 '08 #3
Sorry, change .Item to .Cells.
"bobk" <in**@minuteman-systems.comwrote in message
news:9e**********************************@d77g2000 hsb.googlegroups.com...
On Jul 19, 4:42 pm, "Scott M." <s-...@nospam.nospamwrote:
A DataGrid is .NET is made up of collections of rows and columns. These
collections contain row and column objects respectively. In .NET, all
collections are zero-based.

So, if you wish to get to the second row of a DataGrid, you'd type:

dataGridName.Rows(1)

and if you wanted to get access to the third column (called items in a row
object), you'd type:

dataGridName.Rows(1).Item(2)

...and if you wanted to place a value in that column, you'd type:

dataGridName.Rows(1).Item(2) = "something"

One word of advice as you move to .NET from VB 6.0; understand the working
in VB .NET is not at all like working in VB 6.0, in terms of the objects
you'll use and the way the language is compiled. It is actually best to
discard your VB 6.0 knowledge (hard as that may be to accept) and start
fresh.

-Scott

"bobk" <i...@minuteman-systems.comwrote in message

news:01**********************************@f36g2000 hsa.googlegroups.com...
My apologies upfront for what I am sure is a newbie question, but I
have been unable to find an answer via search.
I am a VB6 programmer trying to write programs in VB 2008 Express.
I have an 'unbound' datagrid control view on a form and just want to
be able to write text to individual cells.
I can programatically set the number of rows and cells, but have been
unable to select and/or write to cells.
Simple things that worked for the FlexGrid view in VB6 don't seem to
apply;
I can't just write (on a command button click event)
me.datgridview1.row= 1 ; me.datgridview1.col= 1 ;
me.datgridview1.text= "something"
These all seem to result in syntax errors.
How do I do a simple thing like this?
Thanks in advance- Hide quoted text -

- Show quoted text -
Thank you but that does not work.

It gives an error message that "item is not a member of
System.Windows.Forms.DataGridViewRow"

Here is the whole procedure;

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Me.DataGridView1.Rows(1).item(1) = "something"
End Sub

Is there some declaration or something I have to include to get it to
recognize the control/collection?

Bob
Jul 20 '08 #4
Scott,

I partially respectful disagree this sentence below with you (and I think
you agree with that because your text can in my idea be read in different
ways).
>
One word of advice as you move to .NET from VB 6.0; understand the working
in VB .NET is not at all like working in VB 6.0, in terms of the objects
you'll use and the way the language is compiled. It is actually best to
discard your VB 6.0 knowledge (hard as that may be to accept) and start
fresh.
The first part I agree of course completely, however the second part not.

The first part is about dotNet and OOP.

The second part is about a program languages that can be used with dotNet.
The VB6 language part is still almost completely the same inside VB9
(although that is extended) and that part can be used to create applications
using VB. However, now in a OOP way, which is (mostly) completely different
from the way VB6 developpers did it before they knew the advantages of OOP.

See this text just as a simple addition for the OP, before he becomes scared
what is absolute not necessary.

=Cor

Jul 20 '08 #5
bobk wrote:
>
"dataGridName.Rows(1).Item(2) "

"item is not a member of System.Windows.Forms.DataGridViewRow"

I'm sure there's something else I'm doing wrong and would greatly
appreciate any help figuring out what it is.
Not using Intellisense? :)

You have a DataGridView, not a DataGrid. So you need to use its properties:

DataGridView1.Item(2, 1).Value = "Boo"
or
DataGridView1.Rows(1).Cells(2).Value = "Boo"

Jul 20 '08 #6
On Jul 20, 3:36*pm, "Steve Gerrard" <mynameh...@comcast.netwrote:
bobk wrote:
"dataGridName.Rows(1).Item(2) "
"item is not a member of *System.Windows.Forms.DataGridViewRow"
I'm sure there's something else I'm doing wrong and would greatly
appreciate any help figuring out what it is.

Not using Intellisense? :)

You have a DataGridView, not a DataGrid. So you need to use its properties:

* * DataGridView1.Item(2, 1).Value = "Boo"
or
* * DataGridView1.Rows(1).Cells(2).Value = "Boo"
That does it.

Thank You.
Jul 20 '08 #7
>COMMENT: At each step the list of choices is sometimes long and often
>not obvious, at least to someone coming from VB6 to .NET. I have a
text book I'm working with and I tried scouring the help files and
searching the newsgroups, but could not find, until here, a clear
explanation of the concepts you are describing. Again I appreciate
that.
This is why I say you should back up and learn more about object-oriented
programming before diving into VB .NET (or any .NET language).

When you see that dropdown list (called IntelliSense) the icons next to the
items you see indicate what kind of "member" you are looking at; the
pointing hand icon depicts a "property" and the pink block depicts a
"method". Knowing that properties describe something and that methods are
actions (functions) that can be performed usually allows you to immediately
rule out one type on the list. When that leaves you with a subset of
choices, you can simply select the one that seems like it may be what you
are looking for and as soon as it is in your code, simply press F1, which
will immediately take you to the help for that choice. You can then read
about that choice and see if it is what you are looking for.

At last count, there are over 50,000 types in the .NET Framework!!! Each one
has its own properties and methods and no one knows what they all do. The
best path is to learn how to use Visual Studio to learn the .NET Framework.

Good luck.


Jul 21 '08 #8

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

Similar topics

5
by: Earl | last post by:
I want to fire a database update off of a single change to a single cell in the datagrid. This apparently cannot be done using keypress, keyup, keydown, etc. I've read George Shepard's FAQ and...
0
by: Bob | last post by:
I attached the properties list of the column in a datagridview. The datagridview is bound. Note that the cell visible property is set to false and while looking at the datagridview in the VS IDE...
3
by: David Veeneman | last post by:
I'm trying to set images in a bound DataGridView image column. My enum has three possible values, and I have an image that I want to show for each value: EnumValue.OK --GreenLight.gif...
2
by: galletg | last post by:
please; how to write by code in a datagrid view cell a text in a textbox. thank you for your help. georges gallet
1
by: Dranizz | last post by:
I want to set the value of a cell in a datagridview. DatagridView.CurrentRow.Cells(CEllName).value = "Blabla" When I do this in code and when it's the first cell I edit in a new row, it does...
0
by: LostInMD | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
0
by: RKT | last post by:
I have a DataGridView bound to an MS Access table. This is a single- user application. When the User is adding or editing a row, the User may click on a Control elsewhere. That Control has context...
12
by: cj | last post by:
When viewing a datatable in a datagridview one of the columns in it is a "note" field which can be quite long. I would like to have the note field of the currently selected row of the datagrid...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.