This example shows how to identify a data cell with the specified value and focus it. To do this, click the 'Find Next' button. The search is performed starting from the currently focused row.
<Window x:Class="DXSample_FocusingCells.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" Title="Focusing Cells" Height="300" Width="491">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="32" />
</Grid.RowDefinitions>
<dxg:GridControl Margin="5" Name="grid" AutoGenerateColumns="AddNew">
<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True" ShowGroupPanel="False" AllowGrouping="False" NavigationStyle="Cell" />
</dxg:GridControl.View>
</dxg:GridControl>
<Button Grid.Row="1" HorizontalAlignment="Left" Margin="2" Click="Button_Click">
Find Next</Button>
</Grid>
</Window>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DevExpress.Xpf.Grid;
namespace DXSample_FocusingCells {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
grid.ItemsSource = new nwindDataSetTableAdapters.ProductsTableAdapter().GetData();
}
private void Button_Click(object sender, RoutedEventArgs e) {
if (grid.VisibleRowCount == 0) return;
int rowHandle = view.FocusedRowHandle + 1;
while (Convert.ToDouble(grid.GetCellValue(rowHandle, "UnitPrice")) != 10 &&
grid.IsValidRowHandle(rowHandle)) {
rowHandle++;
}
if (grid.IsValidRowHandle(rowHandle)) {
grid.CurrentColumn = grid.Columns["UnitPrice"];
view.FocusedRowHandle = rowHandle;
}
}
}
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports DevExpress.Xpf.Grid
Namespace DXSample_FocusingCells
Partial Public Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
grid.ItemsSource = New nwindDataSetTableAdapters.ProductsTableAdapter().GetData()
End Sub
Private Sub Button_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
If grid.VisibleRowCount = 0 Then
Return
End If
Dim rowHandle As Integer = view.FocusedRowHandle + 1
Do While Convert.ToDouble(grid.GetCellValue(rowHandle, "UnitPrice")) <> 10 AndAlso grid.IsValidRowHandle(rowHandle)
rowHandle += 1
Loop
If grid.IsValidRowHandle(rowHandle) Then
grid.CurrentColumn = grid.Columns("UnitPrice")
view.FocusedRowHandle = rowHandle
End If
End Sub
End Class
End Namespace