Skip to main content

Empty Space

  • 3 minutes to read

Empty space appears when cells and (optionally) group rows do not occupy an entire View’s area. This can occur when there are few rows, total column widths are less than a View’s width or as a result of vertical scrolling.

 

VisualElems_GridView_EmptySpace

 

The GridViewAppearances.Empty property allows you to modify this area’s appearance. You can also handle the CustomDrawEmptyForeground event to manually paint this region. The “CustomDrawEmptyForeground” module in the DevExpress Demo Center illustrates how to add a clickable link to the empty space area. This link is shown when a Data Grid filter returns no results, and allows users to modify the filter condition.

Run Demo: CustomDrawEmptyForeground

string searchName = string.Empty;
gridView.ActiveFilterCriteria = new BinaryOperator("Name", searchName);

// Initialize variables used to paint View's empty space in a custom manner
Font noMatchesFoundTextFont = new Font("Tahoma", 10);
Font trySearchingAgainTextFont = new Font("Tahoma", 15, FontStyle.Underline);
Font trySearchingAgainTextFontBold = new Font(trySearchingAgainTextFont, FontStyle.Underline | FontStyle.Bold);
SolidBrush linkBrush = new SolidBrush(DevExpress.Skins.EditorsSkins.GetSkin(
    DevExpress.LookAndFeel.UserLookAndFeel.Default.ActiveLookAndFeel).Colors["HyperLinkTextColor"]);
string noMatchesFoundText = "No matches found";
string trySearchingAgainText = "Try searching again";
Rectangle noMatchesFoundBounds = Rectangle.Empty;
Rectangle trySearchingAgainBounds = Rectangle.Empty;
bool trySearchingAgainBoundsContainCursor = false;
int offset = 10;


gridView.CustomDrawEmptyForeground += (s, e) => {
    e.DefaultDraw();
    e.Appearance.Options.UseFont = true;
    e.Appearance.Font = noMatchesFoundTextFont;
    //Draw the noMatchesFoundText string
    Size size = e.Appearance.CalcTextSize(e.Cache, noMatchesFoundText, e.Bounds.Width).ToSize();
    int x = (e.Bounds.Width - size.Width) / 2;
    int y = e.Bounds.Y + offset;
    noMatchesFoundBounds = new Rectangle(new Point(x, y), size);
    e.Appearance.DrawString(e.Cache, noMatchesFoundText, noMatchesFoundBounds);
    //Draw the trySearchingAgain link
    e.Appearance.Font = trySearchingAgainBoundsContainCursor ?
        trySearchingAgainTextFontBold : trySearchingAgainTextFont;
    size = e.Appearance.CalcTextSize(e.Cache, trySearchingAgainText, e.Bounds.Width).ToSize();
    x = noMatchesFoundBounds.X - (size.Width - noMatchesFoundBounds.Width) / 2;
    y = noMatchesFoundBounds.Bottom + offset;
    size.Width += offset;
    trySearchingAgainBounds = new Rectangle(new Point(x, y), size);
    e.Appearance.DrawString(e.Cache, trySearchingAgainText, trySearchingAgainBounds, linkBrush);
};

gridView.MouseMove += (s, e) => {
    trySearchingAgainBoundsContainCursor = trySearchingAgainBounds.Contains(e.Location);
    gridControl.Cursor = trySearchingAgainBoundsContainCursor ? Cursors.Hand : Cursors.Default;
    gridView.InvalidateRect(trySearchingAgainBounds);
};

gridView.MouseDown += (s, e) => {
    if(trySearchingAgainBoundsContainCursor) {
        searchName = XtraInputBox.Show(string.Format("Enter {0}", "Name"), string.Format(
            "Enter {0} dialog", "Name"), searchName);
        gridView.ActiveFilterCriteria = new BinaryOperator("Name", searchName);
    }
};
See Also