abraXus
  • abraXus
  • Advanced Member Topic Starter
2023-01-07T22:17:17Z
I am using the IGButtonColumnManager and when I "hide" the button, the cell is just blank and useless. I would like whatever text would normally be there to be there instead.
I am trying to get the default text to display in a cell and act normally (except for editing, I do not need it editable) when the button is hidden.
I assume this requires use of the CustomDrawCellForeground event

So I loaded the Demo for ButtonColumnManager and added this to it to see if I could get it working, and I am close, but could use a little assistance.
Here is what i came up with. It works for the most part, but I am stuck on 2 things.

When the cell is selected the text turns white (good) but then a different cell is selected, the text color does not change back to black (bad).
I would like to match the alignment as well but as you can see from the commented out code, there is something I do not understand.
I am not experienced with CustomDraw events.

Ideally, I would love for this functionality to just be included in the iGButtonColumnManager. Is that maybe possible? So I wouldn't have to write my own CustomDrawCellForeground?

I am also open to completely re-writing this as I bet there is a simpler way to do it.
Please offer some suggestions if you can.



	
        Private Sub fGrid_CustomDrawCellForeground(sender As Object, e As iGCustomDrawCellEventArgs) Handles fGrid.CustomDrawCellForeground
		If CStr(fGrid.Rows(e.RowIndex).Tag) = "Hide cell button" And CStr(fGrid.Cols(e.ColIndex).Tag) = iGButtonColumnManager.BUTTON_COLUMN_TAG Then
			Dim StringSize As SizeF = e.Graphics.MeasureString(fGrid.Cells(e.RowIndex, e.ColIndex).Text, fGrid.Font)

			Dim brush As New SolidBrush(Color.Black)
			If fGrid.CurCell IsNot Nothing Then
				If fGrid.CurCell Is fGrid.Cells(e.RowIndex, e.ColIndex) Then
					brush.Color = fGrid.CurCell.EffectiveForeColor
				Else
					brush.Color = fGrid.SelCellsForeColor
				End If
			Else
				brush.Color = fGrid.ForeColor
			End If

			Dim xLoc As Single
			Dim drawFormat As New StringFormat

			'Select Case fGrid.Cells(e.RowIndex, e.ColIndex).TextAlign
			'Case iGContentAlignment.TopCenter, iGContentAlignment.MiddleCenter, iGContentAlignment.BottomCenter

			drawFormat.Alignment = StringAlignment.Center
			xLoc = e.Bounds.X + CSng(e.Bounds.Width / 2)

			'Case iGContentAlignment.TopLeft, iGContentAlignment.MiddleLeft, iGContentAlignment.BottomLeft
			'	drawFormat.Alignment = StringAlignment.Near
			'	xLoc = e.Bounds.X + 10
			'Case iGContentAlignment.TopRight, iGContentAlignment.MiddleRight, iGContentAlignment.BottomRight
			'	drawFormat.Alignment = StringAlignment.Far
			'	xLoc = e.Bounds.X + StringSize.Width
			'End Select

			Dim yLoc As Single = e.Bounds.Y + CSng(e.Bounds.Height / 2) - CSng(StringSize.Height / 2)
			e.Graphics.DrawString(fGrid.Cells(e.RowIndex, e.ColIndex).Text, fGrid.Font, brush, xLoc, yLoc, drawFormat)
		End If
	End Sub
Igor/10Tec
2023-01-09T15:59:47Z
Why don't simply disable custom drawing and use the native cell text drawing?