473,385 Members | 1,796 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,385 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 14536

"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...
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...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.