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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

search in one column of a sfdatagrid

Thread ID:

Created:

Updated:

Platform:

Replies:

128241 Jan 10,2017 01:48 PM UTC Jan 11,2017 04:03 PM UTC WPF 1
loading
Tags: SfDataGrid
Philipp Reiter
Asked On January 10, 2017 01:48 PM UTC

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

 

Gnanasownthari Thirugnanam [Syncfusion]
Replied On 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.  

 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;