DavidGreenfield
asked on
Datagrid View - Cell Padding and adding an icon
Hi there
I have a datagrid view, one column and many rows. For each cell I want to pad the cell so the text is indented by a few pixels and display a status icon *before* the text.
I thought below was the most obvious to indent a cell:
DataGridView1.DefaultCellS tyle.Paddi ng.Left = 80
but I get the error message: Expression is a value and therefore cannot be the target of an assignment.
And there doesn't seem to be an option to show a background image on a cell :oS
Any ideas?
I have a datagrid view, one column and many rows. For each cell I want to pad the cell so the text is indented by a few pixels and display a status icon *before* the text.
I thought below was the most obvious to indent a cell:
DataGridView1.DefaultCellS
but I get the error message: Expression is a value and therefore cannot be the target of an assignment.
And there doesn't seem to be an option to show a background image on a cell :oS
Any ideas?
ASKER
Hi Bob
1) works fantastically well!
2) When I tried this the image doesn't appear in all cells, and when I move the scroll bar up and down it seems to add and remove the image randomly against the cells. How do I stop that happening?
Thanks so far!
1) works fantastically well!
2) When I tried this the image doesn't appear in all cells, and when I move the scroll bar up and down it seems to add and remove the image randomly against the cells. How do I stop that happening?
Thanks so far!
2) That sounds like the graphics are not persisting. When you scroll, does the CellPainting event fire?
Bob
Bob
ASKER
Yes it does appear that the cell painting is firing each time I scroll
Can you show me what you came up with, then?
Bob
Bob
ASKER
Not sure I understand
To check it fired I just output the time in the debug window and checked on scrolling that this piece of code was being fired. Otherwise on moving between screens it also fires - so i can't walk through the code.
The output is exactly the same, on scrolling sometimes the picture is shown, sometimes not. Because it fires so much I can't tell how many times it fires against each cell on a scroll. On one mouse click on the scroll there appears to be 2 fires however :oS
To check it fired I just output the time in the debug window and checked on scrolling that this piece of code was being fired. Otherwise on moving between screens it also fires - so i can't walk through the code.
The output is exactly the same, on scrolling sometimes the picture is shown, sometimes not. Because it fires so much I can't tell how many times it fires against each cell on a scroll. On one mouse click on the scroll there appears to be 2 fires however :oS
I am sorry for the unclear question. Can you show me the code that you came up with to solve the problem? I want to make sure that the implementation is what it needs to be to get the job done correctly.
Bob
Bob
ASKER
I have not actually solved the problem yet
I have a split panel with left docking, flexgrid in the top panel. I am adding data to the grid using
DataGridView1.Rows.Add(men u_xml_node .Attribute s.GetNamed Item("titl e").Value)
then I have the below:
Private Sub CellPainter(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEv entArgs) Handles DataGridView1.CellPainting
e.Graphics.DrawImage(My.Re sources.ar row, 0, 0)
Debug.Print(System.DateTim e.Now())
End Sub
initially before I have started scrolling only the top row has an image in its cell. On scrolling they randomly appear in different rows.
Thanks so far
I have a split panel with left docking, flexgrid in the top panel. I am adding data to the grid using
DataGridView1.Rows.Add(men
then I have the below:
Private Sub CellPainter(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEv
e.Graphics.DrawImage(My.Re
Debug.Print(System.DateTim
End Sub
initially before I have started scrolling only the top row has an image in its cell. On scrolling they randomly appear in different rows.
Thanks so far
David,
Is the image the only thing in the cell, is there something like text?
Bob
Is the image the only thing in the cell, is there something like text?
Bob
ASKER
Yes there is text in the cell as well. Will try it without text
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nope, doesn't seem to be making a difference. Have tried it in another grid with no formating etc on and still getting the same problem.
Me.DataGridView1.DefaultCe
2) Handle the CellPainting to customize a cell:
Private Sub CellPainter(ByVal sender As Object, ByVal e As DataGridViewCellPaintingEv
e.Graphics.DrawImage(Image
End Sub
Bob