|
1 | | -# wpf-gridcontrol-input-message |
2 | | -This repository contains the samples that demonstrates various options in input message feature of wpf gridcontrol. |
| 1 | +# WPF GridControl input message |
| 2 | + |
| 3 | +This repository contains the samples that demonstrates various options in input message feature of [WPF GridControl](https://help.syncfusion.com/wpf/gridcontrol/overview). |
| 4 | + |
| 5 | +### Input Message Tip for row and column |
| 6 | + |
| 7 | +The input message tip can be displayed for any row or column by setting the [ShowDataValidationTooltip](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridStyleInfo.html#Syncfusion_Windows_Controls_Grid_GridStyleInfo_ShowDataValidationTooltip) and the message tip can be customized by setting [DataValidationTooltip](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridStyleInfo.html#Syncfusion_Windows_Controls_Grid_GridStyleInfo_DataValidationTooltip) property. |
| 8 | + |
| 9 | +``` csharp |
| 10 | +//Adding input message tip for specific row |
| 11 | +grid.Model.RowStyles[1].DataValidationTooltip = "Hello"; |
| 12 | +grid.Model.RowStyles[1].ShowDataValidationTooltip = true; |
| 13 | + |
| 14 | +//Adding input message tip for specific column |
| 15 | +grid.Model.ColStyles[1].DataValidationTooltip = "Hello"; |
| 16 | +grid.Model.ColStyles[1].ShowDataValidationTooltip = true; |
| 17 | +``` |
| 18 | + |
| 19 | +An another way to set the input message tip for specific row and column. |
| 20 | + |
| 21 | +``` csharp |
| 22 | +//Add input message tip for specific row |
| 23 | +for (int i = 1; i <= 4; i++) |
| 24 | +{ |
| 25 | + string comment = grid.Model[1, 0].CellValue + " :\nPopulation rate in " + grid.Model[1, i].ColumnIndex + " is " + grid.Model[1, i].CellValue; |
| 26 | + grid.Model[1, i].DataValidationTooltip = comment; |
| 27 | + grid.Model[1, i].ShowDataValidationTooltip = true; |
| 28 | +} |
| 29 | + |
| 30 | +//Add input message tip for specific column |
| 31 | +for (int i = 1; i <= 4; i++) |
| 32 | +{ |
| 33 | + string comment = grid.Model[i, 0].CellValue + " :\nPopulation rate in " + grid.Model[i, 2].RowIndex + " is " + grid.Model[i, 2].CellValue; |
| 34 | + grid.Model[i, 2].DataValidationTooltip = comment; |
| 35 | + grid.Model[i, 2].ShowDataValidationTooltip = true; |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +### Set Input Message Tip using QueryCellInfo event |
| 40 | + |
| 41 | +You can set the input message tip for specific cell or row or column by using [QueryCellInfo](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridModel.html#Syncfusion_Windows_Controls_Grid_GridModel_QueryCellInfo) event. |
| 42 | + |
| 43 | +``` csharp |
| 44 | +private void Grid_QueryCellInfo(object sender, Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventArgs e) |
| 45 | +{ |
| 46 | + e.Style.ShowDataValidationTooltip = true; |
| 47 | + |
| 48 | + //Show message tip for specific cell |
| 49 | + if (e.Cell.RowIndex == 1 && e.Cell.ColumnIndex == 1) |
| 50 | + e.Style.DataValidationTooltip = e.Style.GridModel[1, 0].CellValue + ": \nPopulation rate in " + e.Style.ColumnIndex + " is " + e.Style.CellValue.ToString(); |
| 51 | + |
| 52 | + // Show message tip for row. |
| 53 | + if (e.Cell.ColumnIndex > 0 && e.Cell.RowIndex == 1) |
| 54 | + e.Style.DataValidationTooltip = e.Style.GridModel[1, 0].CellValue + ": \nPopulation rate in " + e.Style.ColumnIndex + " is " + e.Style.CellValue.ToString(); |
| 55 | + |
| 56 | + // Show message tip for column. |
| 57 | + if (e.Cell.RowIndex > 0 && e.Cell.ColumnIndex == 2) |
| 58 | + e.Style.DataValidationTooltip = e.Style.GridModel[e.Style.RowIndex, 0].CellValue + ": \nPopulation rate in " + e.Style.RowIndex + " is " + e.Style.CellValue.ToString(); |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +### Customize the Input Message Tip |
| 63 | + |
| 64 | +The input message tip can be customized by defining DataTemplate. The DataTemplate can be assigned to the [GridStyleInfo.DataValidationTooltipTemplateKey](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridStyleInfo.html#Syncfusion_Windows_Controls_Grid_GridStyleInfo_DataValidationTooltipTemplateKey) property. If you are using inputTextmessage1 then you need to assign template to its corresponding template key property namely `GridStyleInfo.DataValidationTooltipTemplateKey`. |
| 65 | + |
| 66 | +[GridStyleInfo](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridStyleInfo.html) which holds cell information is the `DataContext` for data template of input message tip. |
| 67 | + |
| 68 | +#### XAML |
| 69 | + |
| 70 | +``` xml |
| 71 | +<Window.Resources> |
| 72 | + <DataTemplate x:Key="inputTextmessage1"> |
| 73 | + <Border BorderBrush="Gray" BorderThickness="2.5" CornerRadius="5"> |
| 74 | + <TextBlock Width="Auto" Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Center" Background="LightBlue" FontSize="14" Foreground="Black" Text="{Binding DataValidationTooltip}" /> |
| 75 | + </Border> |
| 76 | + </DataTemplate> |
| 77 | +</Window.Resources> |
| 78 | +``` |
| 79 | + |
| 80 | +#### C# |
| 81 | + |
| 82 | +``` csharp |
| 83 | +// Set template key to a particular index |
| 84 | +grid.Model[1, 2].DataValidationTooltipTemplateKey = "inputTextmessage1"; |
| 85 | + |
| 86 | +// Using QueryCellInfo event |
| 87 | +private void Grid_QueryCellInfo(object sender, Syncfusion.Windows.Controls.Grid.GridQueryCellInfoEventArgs e) |
| 88 | +{ |
| 89 | + if(e.Cell.RowIndex == 1 && e.Cell.ColumnIndex == 2) |
| 90 | + { |
| 91 | + e.Style.DataValidationTooltip = e.Style.GridModel[1, 0].CellValue + ": \nPopulation rate in " + e.Style.ColumnIndex + " is " + e.Style.CellValue.ToString(); |
| 92 | + e.Style.ShowDataValidationTooltip = true; |
| 93 | + e.Style.DataValidationTooltipTemplateKey = "inputTextmessage1"; |
| 94 | + } |
| 95 | +} |
| 96 | +``` |
0 commit comments