Protected Overloads Overrides Sub OnDrawItem(ByVal e As System.Windows.Forms.DrawItemEventArgs)
Dim rec As New Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height) 'e.Bounds.Width
Dim column As DataGridViewMultiColumnComboColumn = TryCast(ownerCell.OwningColumn, DataGridViewMultiColumnComboColumn)
Dim valuesTbl As DataTable = column.valuesTbl
Dim joinByField As String = column.joinFieldName
Dim NormalText As New SolidBrush(System.Drawing.SystemColors.ControlText)
Dim currentItem As Object = Items(e.Index)
Dim currentText As String = GetItemText(currentItem)
'If there is an item
If (e.Index > -1) Then
'first redraw the normal while background
Dim normalBack As New SolidBrush(Color.White) 'TODO: fix to be system edit box background
e.Graphics.FillRectangle(normalBack, rec)
If DroppedDown AndAlso Not (Margin.Top = rec.Top) Then
Dim currentOffset As Integer = rec.Left
Dim col As DataColumn = valuesTbl.Columns(0)
'now find this text in current join field
Dim itemRows As DataRow() = valuesTbl.[Select](("[" & joinByField & "]='") + currentText & "'")
Dim HightlightedBack As New SolidBrush(System.Drawing.SystemColors.Highlight)
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
'draw selected color background
e.Graphics.FillRectangle(HightlightedBack, rec)
End If
Dim addBorder As Boolean = False
Dim currentRow As DataRow = itemRows(0)
Dim valueItem As Object
For Each dataRowItem As Object In currentRow.ItemArray
valueItem = dataRowItem
Dim value As String = dataRowItem.ToString() 'TODO: support for different types!!!
'Add the vertical boarder line here...
If addBorder Then
'draw dividing line
'currentOffset ++;
Dim gridBrush As New SolidBrush(Color.Gray) 'TODO: make the border color configurable
Dim linesNum As Long = lineWidth
While linesNum > 0
linesNum -= 1
Dim first As New Point(rec.Left + currentOffset, rec.Top)
Dim last As New Point(rec.Left + currentOffset, rec.Bottom)
e.Graphics.DrawLine(New Pen(gridBrush), first, last)
currentOffset += 1
End While
'currentOffset++;
Else
addBorder = True
End If
'measure the string that we are going to draw and cut it with wrapping if too large
Dim extent As SizeF = e.Graphics.MeasureString(value, e.Font)
Dim textRec As New Rectangle(currentOffset, rec.Y, CInt(extent.Width), rec.Height)
'now draw the relevant to this column value text
If (e.State And DrawItemState.Selected) = DrawItemState.Selected Then
'draw selected
Dim HightlightedText As New SolidBrush(System.Drawing.SystemColors.HighlightText)
'now redraw the backgrond in order to wrap the previous field if was too large
e.Graphics.FillRectangle(HightlightedBack, currentOffset, rec.Y, fixedAlignColumnSize, extent.Height)
'draw text as is
e.Graphics.DrawString(value, e.Font, HightlightedText, textRec)
Else
'now redraw the backgrond it order to wrap the previous field if was too large
e.Graphics.FillRectangle(normalBack, currentOffset, rec.Y, fixedAlignColumnSize, extent.Height)
'draw text as is
e.Graphics.DrawString(value, e.Font, NormalText, textRec)
End If
'advance the offset to the next position
currentOffset += fixedAlignColumnSize
Next
End If
End If
End Sub
|