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?
abraXus
  • abraXus
  • Advanced Member Topic Starter
2023-02-08T03:10:14Z
Using the IGButtonColumnManager as a starting point, I created a class called IGButtonCells

Instead of using Attach, i created AddButton


	Public Sub AddButton(ByVal cell As iGCell, Optional txt As String = "")
		With cell
			.Selectable = False
			.CustomDrawFlags = iGCustomDrawFlags.Foreground
			.ContentIndent = New iGIndent(0, 0, 0, 0)
			If txt.Length > 0 Then .Value = txt
		End With
		ButtonCells.Add(cell)
	End Sub

	Public Sub AddButton(ByVal cell As iGFooterCell, Optional txt As String = "")
		With cell
			.CustomDrawFlags = iGCustomDrawFlags.Foreground
			.ContentIndent = New iGIndent(0, 0, 0, 0)
			If txt.Length > 0 Then .Value = txt
		End With
		ButtonCells.Add(cell)
	End Sub

Which is used to track which cells are using a button.

Friend ReadOnly ButtonCells As New List(Of Object)

And gave it an initializer.


	Public Sub New(Grid As iGrid)
		fGrid = Grid
	End Sub

And this is how i determine if it needs to be drawn.


	Private Function IsCellButton(ByVal rowIndex As Integer, ByVal colIndex As Integer) As Boolean
		Return ButtonCells.Find(Function(x) x.RowIndex = rowIndex And x.ColIndex = colIndex) IsNot Nothing
	End Function

The only things I cannot get working are the hover effects for cells in the footer.

Apparently iGCustomDrawFooterCellEventArgs does not have a State property, so I forced it to Normal all the time.


			' Determine the button state.
			Dim myState As VisualStyles.PushButtonState
			'Select Case e.State
			'	Case iGControlState.Normal
			'		myState = VisualStyles.PushButtonState.Normal
			'	Case iGControlState.Hot
			'		myState = VisualStyles.PushButtonState.Hot
			'	Case iGControlState.Pressed
			'		myState = VisualStyles.PushButtonState.Pressed
			'	Case iGControlState.Disabled
			'		myState = VisualStyles.PushButtonState.Disabled
			'End Select
			' do this instead
			myState = VisualStyles.PushButtonState.Normal

Is there a way to get that working?

Also, I have seen others interested in doing this, so is there a place for me to upload a class file for others to use once I finalize this?
I wouldn't mind if you wanted to take the code I came up with and clean it up a bit and offer it to others if you wanted to. It's almost identical to the button column manager, with more subs added to handle the Footer.

(I deleted the initial question as it was not relevant, not realizing your comment would still exist - sorry about that)
Igor/10Tec
2023-02-10T15:33:36Z
I restored your very first post according to your request.

You can upload your class file to this forum if you want to share it with other developers using iGrid. I think it's the right place for doing this :)

As for your request regarding implementing cell states for footer cells - did I miss some point? Do you want to place buttons into footer cells and make them clickable too? Footer cells in iGrid were designed as simplified cells with reduced features, and definitely without the hover and pressed effect. So if you need this, you should implement your own code tracking when the mouse pointer enters/leaves a footer cell and when the mouse button is pressed while the pointer is inside a footer cell. It seems, iGrid has enough tools for that. I mean, first of all, the FooterCellMouseEnter/FooterCellMouseLeave/FooterCellMouseDown events.