473,503 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datagridview cell - get row/column info for updating data- how?

Hello,

If I want to update data displayed in a datagrideview/datagridview cell, how
can I determine what cell I am updating? I am looking at the click event
below, for example. Can I get information from the sender object or the
EventArgs? How?

Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGridView1.Click
Console.WriteLine("row number of cell is ?")
Console.Writeline("Column Name of Cell is ?")
End Sub

Thanks,
Rich

May 26 '06 #1
3 14551

"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
Hello,

If I want to update data displayed in a datagrideview/datagridview cell,
how
can I determine what cell I am updating? I am looking at the click event
below, for example. Can I get information from the sender object or the
EventArgs? How?

Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGridView1.Click
Console.WriteLine("row number of cell is ?")
Console.Writeline("Column Name of Cell is ?")
End Sub

Thanks,
Rich


I did this by having an event handler of:

private sub dViewWeek_CellMouseDown(ByVal sender As Object, ByVal e as
DataGridViewCellMouseEventArgs)

then you get e.ColumnIndex and e.RowIndex


May 26 '06 #2
Thanks, yes. I tried something similar which also gave me some values for e:

Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellEnter
Console.WriteLine(DataGridView1.Columns(e.ColumnIn dex).Name.ToString
& " " & DataGridView1.Rows(e.RowIndex).ToString)
Console.WriteLine("*" &
DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex ).Value.ToString & "*")

End Sub
I guess I will just have to play around with the datagridview to get the
hang of it. Would you know how to individually format a cell in a datagrid
view? I noticed that if I do this:

Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellFormattingEve ntArgs) Handles
DataGridView1.CellFormatting
e.CellStyle.ForeColor = Color.Red
e.CellStyle.BackColor = Color.Yellow
End Sub

all the cells in the grid have red text and a yellow background. How can I
do that only to the cell that I click?
"james" wrote:

"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:41**********************************@microsof t.com...
Hello,

If I want to update data displayed in a datagrideview/datagridview cell,
how
can I determine what cell I am updating? I am looking at the click event
below, for example. Can I get information from the sender object or the
EventArgs? How?

Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGridView1.Click
Console.WriteLine("row number of cell is ?")
Console.Writeline("Column Name of Cell is ?")
End Sub

Thanks,
Rich


I did this by having an event handler of:

private sub dViewWeek_CellMouseDown(ByVal sender As Object, ByVal e as
DataGridViewCellMouseEventArgs)

then you get e.ColumnIndex and e.RowIndex


May 26 '06 #3

"Rich" <Ri**@discussions.microsoft.com> wrote in message
news:40**********************************@microsof t.com...
Thanks, yes. I tried something similar which also gave me some values for
e:

Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellEnter

Console.WriteLine(DataGridView1.Columns(e.ColumnIn dex).Name.ToString
& " " & DataGridView1.Rows(e.RowIndex).ToString)
Console.WriteLine("*" &
DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex ).Value.ToString & "*")

End Sub
I guess I will just have to play around with the datagridview to get the
hang of it. Would you know how to individually format a cell in a
datagrid
view? I noticed that if I do this:

Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e
As
System.Windows.Forms.DataGridViewCellFormattingEve ntArgs) Handles
DataGridView1.CellFormatting
e.CellStyle.ForeColor = Color.Red
e.CellStyle.BackColor = Color.Yellow
End Sub

all the cells in the grid have red text and a yellow background. How can
I
do that only to the cell that I click?


Forgive the C# code - but you should be able to use something like:

DataGridViewCellStyle myNewStyle = new DataGridViewCellStyle();
myNewStyle.BackColor = Color.Red;
myNewStyle.ForeColor = Color.Blue;
dataGridView1.Rows[0].Cells[2].Style = myNewStyle;
May 26 '06 #4

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

Similar topics

2
16646
by: Marc Solé | last post by:
Hello, I want to insert an image to a specific column of a dataGridWiew. I explain what I'm doing: - I define the ColumnType as a DataGridViewImageColumn. - I select the image (an icon of...
2
24510
by: bob | last post by:
Can anyone tell me the best way to update a dataset while it is being edited/viewed in the DataGridView control? Is this something that should be inserted into one of the grid's events? or should...
7
10039
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works...
4
21269
by: Hexman | last post by:
Hello All, I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it. ------------------------------- 1) Add a cb to the dgv,...
7
16326
by: Ryan | last post by:
I have a DataGridView which displays numeric (Int32) data from an underlying database. I want the numbers to be displayed in numeric format "#,###" (with commas). I want to also limit the user so...
7
15611
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...
2
6101
by: mrstrong | last post by:
Gday, Why would all my checkboxes inside a datagridview stop working (ie checked state not updating when user clicks) when the datagridview's editmode property is changed to "EditOnEnter"? It...
1
3353
by: TG | last post by:
Hi! I have an application in which I have some checkboxes and depending which ones are checked those columns will show in the datagridview from sql server or no. After that I have 2 buttons:...
0
5635
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be...
0
7198
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
7319
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...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
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
5570
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
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.