We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

search in one column of a sfdatagrid

Hi,
I have a sfDataGrid with three GridTextColumn and two GridTemplateColumn.CellTemplate (DatePiker) columns. I want to search and programmatically select in the first column (which is a GridTextColumn). Using the SearchHelper.Search fails with NullReferenceExceptions. I think they are cause from searching over the GridTemplateColumn.


Is it possible to point the SearchHelper to the first column only?

Or how can I export a list from the first column only to search in manually?

Thanks in advance, Philipp

 

1 Reply

GT Gnanasownthari Thirugnanam Syncfusion Team January 11, 2017 04:03 PM UTC

Hi Philipp, 

We have analyzed your query. We are unable to reproduce your reported issue “Nullreference Exception throws ” when search and programmatically select the first column (GridTexColumn). You can achieve your requirement in below mentioned way. 

Query 1: Possible to point the SearchHelper to the first column 
 
You can achieve your requirement customize the SearchHelper class and  search first column only based on mapping name like below code example. 

Code Example (C#): 
 
public MainWindow() 
{ 
    InitializeComponent(); 
    this.dataGrid.SearchHelper = new SearchHelperExt(this.dataGrid);            
 
 
public class SearchHelperExt : SearchHelper 
{ 
    public SearchHelperExt(SfDataGrid datagrid) 
        : base(datagrid) 
    { 
    } 
   
    protected override bool SearchCell(DataColumnBase column, object record, bool ApplySearchHighlightBrush) 
    { 
        if (column == null) 
            return false; 
        if (column.GridColumn.MappingName == "OrderID") 
        { 
            return base.SearchCell(column, record, ApplySearchHighlightBrush); 
        } 
        else 
            return false; 
    } 
} 

Query 2: Export a list from the first column only to search in manually 
 
Export the searched record like below code example 
 
Code Example (C#): 
 
private void Shift_Click(object sender, RoutedEventArgs e) 
{            
    this.dataGrid.SearchHelper.FindNext(this.TextBox.Text); 
    this.dataGrid.SelectionController.MoveCurrentCell(this.dataGrid.SearchHelper.CurrentRowColumnIndex); 
    var recored = this.dataGrid.SelectedItem;            
    var viewmodel = this.dataGrid.DataContext as ViewModel; 
    if (previousrowColumnIdex != this.dataGrid.SearchHelper.CurrentRowColumnIndex) 
        viewmodel.SearchItem.Add(recored); 
    previousrowColumnIdex = this.dataGrid.SearchHelper.CurrentRowColumnIndex;            
} 
 

We have prepared the sample as per your requirement , you can download the same from below mentioned location. 

Sample location: 

Regards, 
Gnanasownthari T.  

 


Loader.
Live Chat Icon For mobile
Up arrow icon