I have developed an application in vb.net with MS access. In a form I have a Datagridview and I retrieve the data by databindingsource.
I am copying the data from datagridview to textbox and then to another table in database.
I want- after being copied the color of selected row should be changed , so next time whenever I retrive data in datagridview, the color of selected rows should have been changed.
Is this possible?
Satyam_1 0 Junior Poster
Recommended Answers
Jump to Post— Reverend Jim 6,665Example. Iterate over all columns to change the entire row.
dgvNames.Rows(row).Cells(0).Style.BackColor = Color.Thistle
Jump to Post— Minimalist 96Another method would be:
Set: SelectionMode to FullRowSelect of your datagridPrivate Sub DataGridView1_CellMouseDown(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView1.CellMouseDown For Each row As DataGridViewRow In DataGridView1.Rows DataGridView1.RowsDefaultCellStyle.SelectionBackColor = Color.Red If e.RowIndex > -1 Then DataGridView1.Rows(e.RowIndex).Selected = True End If Next End Sub
Jump to Post— Minimalist 96Well, show the code you have sofar,
otherwise put your copying code between lines 2 and 3:For Each row As DataGridViewRow In DataGridView1.Rows 'Put your code here DataGridView1.RowsDefaultCellStyle.SelectionBackColor = Color.Red
Jump to Post— Santanu.Das 125Yes,You can do this after necessary changes in the row.
just store the CurrentRowIndex value of the selected datagridview row then in button click event after saving the data to the database you can change the color of that row.
Declare a formlaval variable ro hold the datagridview selected row …
Jump to Post— Santanu.Das 125Do not understand.
Please post your full codes on this matter.
All 20 Replies
Reverend Jim 6,665 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Minimalist 96 Posting Pro
Satyam_1 0 Junior Poster
Minimalist 96 Posting Pro
Santanu.Das 125 Santanu Das
Satyam_1 0 Junior Poster
Santanu.Das 125 Santanu Das
Reverend Jim 6,665 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Satyam_1 0 Junior Poster
Santanu.Das 125 Santanu Das
Satyam_1 0 Junior Poster
Minimalist 96 Posting Pro
Reverend Jim 6,665 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Satyam_1 0 Junior Poster
Reverend Jim 6,665 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Satyam_1 0 Junior Poster
Reverend Jim 6,665 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Satyam_1 0 Junior Poster
Reverend Jim 6,665 Hi, I'm Jim, one of DaniWeb's moderators. Moderator Featured Poster
Satyam_1 0 Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.