471,086 Members | 1,016 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,086 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 14368

"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Marc Solé | last post: by
7 posts views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
2 posts views Thread by mrstrong | last post: by

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.