DataGridView Edit row marker

P

Prashwee

Hello All

In my windows application I am using DataGridView as my grid control. I
populated let's say 10 rows of data and modified 3 random rows. I need to
put some sort of Edit Marker in the row header. This can be an image. Please
any one share a code for this implementation.

If i were to save this records, how can I trap those 3 modified rows without
going throgh the whole row set?

Thanks in Advance
Prash
 
B

Brendon Bezuidenhout

Prashwee,

I achieve something similiar when a check box value has changed, add a
DataGridViewImageCell 1st and an ImageList with your Status images in it,
and then trap the CellFormatting event like below

<code>
Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As
DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If e.ColumnIndex = 0 Then setDGVImageStatus(sender, e)
If e.ColumnIndex = 3 Then setDGVSignificant(sender, e)
End Sub
</code>

And add the following Sub for actually setting the Image cell's value -
Don't forget validation :)
I was trapping when value of my ComboBox

''' <summary>
''' Sets the image column of the datagridview dependant on the value
of the ysnResolved column
''' </summary>
''' <param name="sender">The DataGridView who's column needs
altering</param>
''' <param name="e">DataGridViewCellFormattingEventArgs</param>
''' <remarks>Sender as object so that this block can be reused for
both grids</remarks>
Private Sub setDGVImageStatus(ByVal sender As Object, ByVal e As
DataGridViewCellFormattingEventArgs)
Dim colName As String = DirectCast(sender,
DataGridView).Columns(e.ColumnIndex).Name.ToString
'getResolvedDGVColName(sender) just returns the column name of my
DataGridViewCheckBoxCell

If DirectCast(sender,
DataGridView).Rows(e.RowIndex).Cells(getResolvedDGVColName(sender)).Value.Equals(False)
Then
e.Value = iml.Images(1)
Else
e.Value = iml.Images(0)
End If

End Sub

Hope that Helps you out - if not let me know
Brendon
 
P

Prashwee

Hello Brendon

Where do you insert your image in the grid?
Is it in the row header colunm or just another grid cell?
/Prash
 
B

Brendon Bezuidenhout

Pashwee,

Add a DataGridViewImageColumn to the DataGridView and an ImageList to the
form - Failing that search for DataGridViewImageColum and
DataGridViewImageCell on Google

HTH
Brendon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top