ComponentOne True DBGrid for WinForms
Adding a Watermark to the Filter Bar
Data Presentation Techniques > Filtering Data in DataSets > Adding a Watermark to the Filter Bar

You can now easily add a text watermark to the filter bar so that it appears with default text. You can use this watermark to add instructions for filtering text, or adding default values to give users a better understanding of what values can be entered in particular filter bar cells. All you need to do to have text appear in the filter bar is set the FilterWatermark property to a string.

For example in the following code, the FilterWatermark in the first filter bar cell is set to "Filter Me":

To write code in Visual Basic

Visual Basic
Copy Code
' Set the C1DataColumn.FilterWatermark property of the first column.
Me.C1TrueDBGrid1.Columns(0).FilterWatermark = "Filter Me"

To write code in C#

C#
Copy Code
// Set the C1DataColumn.FilterWatermark property of the first column.
this.c1TrueDBGrid1.Columns[0].FilterWatermark = "Filter Me";

Notice that the background color of the filter bar cell with a watermark has changed:


In the following code, the FilterWatermark is set to the value of each column's caption text:

To write code in Visual Basic

Visual Basic
Copy Code
Dim colcount As Integer
colcount = 0
While C1TrueDBGrid1.Columns.Count > colcount
' Set the C1DataColumn.FilterWatermark property of each column to its caption.
C1TrueDBGrid1.Columns(colcount).FilterWatermark = C1TrueDBGrid1.Columns(colcount).Caption
colcount = colcount + 1
End While

To write code in C#

C#
Copy Code
int colcount; 
colcount = 0; 
while (c1TrueDBGrid1.Columns.Count > colcount) 
{ 
    // Set the C1DataColumn.FilterWatermark property of each column to its caption.
    this.c1TrueDBGrid1.Columns[colcount].FilterWatermark = c1TrueDBGrid1.Columns[colcount].Caption; 
    colcount = colcount + 1; 
}

The grid appears like the following:


Notice that when text is filtered, the watermark is no longer visible:


You can change the appearance of the style of the FilterWatermark using the FilterWatermarkStyle property. See How to Use Styles for more information about styles.

See Also