472,955 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,955 software developers and data experts.

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 14495

"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
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
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
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
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
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
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
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
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
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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.