Какой компонент выбрать для отображения таблицы - Visual Basic .NET
Формулировка задачи:
Какой инструмент для подобной таблицы лучше использовать, к сожалению datagridview не подойдет.
Решение задачи: «Какой компонент выбрать для отображения таблицы»
textual
Листинг программы
Public Class CustomDataGridView
Inherits DataGridView
Sub New()
ResizeRedraw = True
DoubleBuffered = True
ColumnHeadersVisible = False
RowHeadersVisible = False
End Sub
Private Sub CustomDataGridView_CellPainting(sender As Object, e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles Me.CellPainting
Try
Dim delmiter As String = "NONE"
If e.Value.ToString.Contains("-") Then
delmiter = "-"
ElseIf e.Value.ToString.Contains("+") Then
delmiter = "+"
End If
If delmiter <> "NONE" Then
Dim _value As String = e.Value.ToString.Split(delmiter)(0).ToString
Dim bonus As String = (delmiter & e.Value.ToString.Split(delmiter)(1)).ToString
Dim _valueWidth As Integer = e.Graphics.MeasureString(_value, e.CellStyle.Font, e.CellBounds.Width).Width
Dim bonusWidth As Integer = e.Graphics.MeasureString(bonus, e.CellStyle.Font, e.CellBounds.Width).Width
e.Handled = True
e.PaintBackground(e.CellBounds, True)
e.Graphics.DrawString(_value, e.CellStyle.Font, Brushes.Black, e.CellBounds.X + 2, e.CellBounds.Y + 5)
Select Case delmiter
Case "-" : e.Graphics.DrawString(bonus, New Font(e.CellStyle.Font.FontFamily, e.CellStyle.Font.SizeInPoints - 1, e.CellStyle.Font.Style), _
Brushes.Red, e.CellBounds.X + _valueWidth + 2, e.CellBounds.Y + 1)
Case "+" : e.Graphics.DrawString(bonus, New Font(e.CellStyle.Font.FontFamily, e.CellStyle.Font.SizeInPoints - 1, e.CellStyle.Font.Style), _
Brushes.Green, e.CellBounds.X + _valueWidth + 2, e.CellBounds.Y + 1)
End Select
End If
Catch : End Try
End Sub
End Class