Пожалуйста, помогите мне сделать график внутри ячейки в представлении таблицы данных visual basic...?
Пожалуйста, помогите мне сделать график внутри ячейки в представлении таблицы данных в Visual Basic (например, график на прилагаемом рисунке)
Я попытался использовать этот код, но ничего не вышло.
[^]
Что я уже пробовал:
#Region "import name spaces" Imports System.Drawing Imports System.ComponentModel #End Region #Region "define columns" Public Class DataGridViewProgressColumn Inherits DataGridViewImageColumn Public Sub New() Me.CellTemplate = New DataGridViewProgressCell End Sub End Class #End Region #Region "define cells" Public Class DataGridViewProgressCell Inherits DataGridViewImageCell Sub New() ValueType = Type.GetType("double") End Sub 'Method required To make the Progress Cell consistent With the Default Image Cell. 'The Default Image Cell assumes an Image As a value, although the value Of the Progress Cell Is an Integer. Protected Overrides Function GetFormattedValue(ByVal value As Object, ByVal rowIndex As Integer, ByRef cellStyle As DataGridViewCellStyle, ByVal valueTypeConverter As TypeConverter, ByVal formattedValueTypeConverter As TypeConverter, ByVal context As DataGridViewDataErrorContexts) As Object Static emptyImage As Bitmap = New Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb) GetFormattedValue = emptyImage End Function Protected Overrides Sub Paint(ByVal g As System.Drawing.Graphics, ByVal clipBounds As System.Drawing.Rectangle, ByVal cellBounds As System.Drawing.Rectangle, ByVal rowIndex As Integer, ByVal cellState As System.Windows.Forms.DataGridViewElementStates, ByVal value As Object, ByVal formattedValue As Object, ByVal errorText As String, ByVal cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, ByVal paintParts As System.Windows.Forms.DataGridViewPaintParts) Dim progressVal As Integer = CType(value, Integer) Dim percentage As Single = CType((progressVal / 100), Single) Dim backBrush As Brush = New SolidBrush(cellStyle.BackColor) Dim foreBrush As Brush = New SolidBrush(cellStyle.ForeColor) ' Call the base class method to paint the default cell appearance. MyBase.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts) If percentage > 0.0 Then ' Draw the progress bar and the text g.FillRectangle(New SolidBrush(Color.FromArgb(163, 189, 242)), cellBounds.X + 2, cellBounds.Y + 2, Convert.ToInt32((percentage * cellBounds.Width - 4)), cellBounds.Height - 4) g.DrawString(progressVal.ToString() & "%", cellStyle.Font, foreBrush, cellBounds.X + 6, cellBounds.Y + 2) Else 'draw the text If Not Me.DataGridView.CurrentCell Is Nothing AndAlso Me.DataGridView.CurrentCell.RowIndex = rowIndex Then g.DrawString(progressVal.ToString() & "%", cellStyle.Font, New SolidBrush(cellStyle.SelectionForeColor), cellBounds.X + 6, cellBounds.Y + 2) Else g.DrawString(progressVal.ToString() & "%", cellStyle.Font, foreBrush, cellBounds.X + 6, cellBounds.Y + 2) End If End If End Sub end class