| MultiRow Windows Forms > Developer's Guide > Using MultiRow > Cell Types > DateTimePickerCell > Display Alternate Text for Null Values (DateTimePickerCell) |
You can show alternate text when the date time picker cell value is null (Nothing in case of Visual Basic) by inheriting or using a custom cell.
If you render the GcMultiRow control using owner draw, you need to add separate processing to render the drop-down button (since you cannot render it before that).
The following code creates a user-defined cell, MyDateTimePickerCell, that inherits the date time picker cell.
Imports System.Windows.Forms
Imports GrapeCity.Win.MultiRow
Public Class MyDateTimePickerCell
Inherits DateTimePickerCell
Protected Overrides Sub OnPaint(ByVal e As CellPaintingEventArgs)
MyBase.OnPaint(e)
If e.Value Is Nothing Then
Dim placeHolder As String = "(None)"
e.PaintBackground(e.ClipBounds)
Dim brushColor As Color = IIf(e.Selected, e.CellStyle.SelectionForeColor, e.CellStyle.ForeColor)
If e.Enabled = False Then brushColor = e.CellStyle.DisabledForeColor
Using brush As New SolidBrush(brushColor)
Dim contentSize As SizeF = e.Graphics.MeasureString(placeHolder, e.CellStyle.Font)
Dim y As Double = e.CellBounds.Y + ((e.CellBounds.Height - contentSize.Height) / 2)
e.Graphics.DrawString(placeHolder, e.CellStyle.Font, brush, e.ClipBounds.X, y)
End Using
End If
End Sub
End Class
|
using System.Drawing;
using GrapeCity.Win.MultiRow;
public class MyDateTimePickerCell : DateTimePickerCell
{
protected override void OnPaint(CellPaintingEventArgs e)
{
base.OnPaint(e);
if (e.Value != null)
{
string placeHolder = "(None)";
Color brushColor = e.Selected ? e.CellStyle.SelectionForeColor : e.CellStyle.ForeColor;
if (e.Enabled == false)
brushColor = e.CellStyle.DisabledForeColor;
using (Brush brush = new SolidBrush(brushColor))
{
SizeF contentSize = e.Graphics.MeasureString(placeHolder, e.CellStyle.Font);
float y = e.CellBounds.Y + ((e.CellBounds.Height - contentSize.ToSize().Height) / 2);
e.Graphics.DrawString(placeHolder, e.CellStyle.Font, brush, e.CellBounds.X, y);
}
}
}
}
|
Use the following steps to use this cell in the designer:
The following code creates a user-defined cell by inheriting the date time picker cell.
Imports GrapeCity.Win.MultiRow
Private Sub GcMultiRow1_CellPainting(ByVal sender As System.Object, ByVal e As CellPaintingEventArgs) Handles GcMultiRow1.CellPainting
Dim gcMultiRow As GcMultiRow = TryCast(sender, GcMultiRow)
If TypeOf gcMultiRow.Rows(e.RowIndex).Cells(e.CellIndex) Is DateTimePickerCell Then
If e.Value Is Nothing Then
Dim placeHolder As String = "(None)"
e.PaintBackground(e.ClipBounds)
Dim brushColor As Color = IIf(e.Selected, e.CellStyle.SelectionForeColor, e.CellStyle.ForeColor)
Using brush As New SolidBrush(brushColor)
Dim contentSize As SizeF = e.Graphics.MeasureString(placeHolder, e.CellStyle.Font)
Dim y As Double = e.CellBounds.Y + ((e.CellBounds.Height - contentSize.Height) / 2)
e.Graphics.DrawString(placeHolder, e.CellStyle.Font, brush, e.ClipBounds.X, y)
End Using
e.PaintErrorIcon(e.ClipBounds)
e.PaintWaveLine(e.ClipBounds)
e.PaintBorder(e.ClipBounds)
e.Handled = True
End If
End If
End Sub
|
using GrapeCity.Win.MultiRow;
private void gcMultiRow1_CellPainting(object sender, GrapeCity.Win.MultiRow.CellPaintingEventArgs e)
{
GcMultiRow gcMultiRow = sender as GcMultiRow;
if (gcMultiRow.Rows[e.RowIndex].Cells[e.CellIndex] is DateTimePickerCell)
{
if (e.Value == null)
{
string placeHolder = "(None)";
e.PaintBackground(e.ClipBounds);
Color brushColor = e.Selected ? e.CellStyle.SelectionForeColor : e.CellStyle.ForeColor;
using (Brush brush = new SolidBrush(brushColor))
{
SizeF contentSize = e.Graphics.MeasureString(placeHolder, e.CellStyle.Font);
float y = e.CellBounds.Y + ((e.CellBounds.Height - contentSize.ToSize().Height) / 2);
e.Graphics.DrawString(placeHolder, e.CellStyle.Font, brush, e.CellBounds.X, y);
}
e.PaintErrorIcon(e.ClipBounds);
e.PaintWaveLine(e.ClipBounds);
e.PaintBorder(e.ClipBounds);
e.Handled = true;
}
}
}
|