# Item Search

## Item Searching

Used to set filter for a TextBoxSearch.

This approach is better than using SearchFilter property (in the XAML editor), because the filter may depend on one or more controls (DataGrid Column) which change their value(s) frequently.

```csharp
public override bool ItemSearching(FrameworkElement sourceControl)
{
    bool result = base.ItemSearching(sourceControl);
    
    if (dgMaterial.IsKeyboardFocusWithin)      //TextBoxSearch in DataGrid
    {
        if (dgMaterial.SelectedColumn == dgMaterialSeriennr)     //DataGrid Column 
        {
            dgMaterialSeriennr.SearchFilter = GetSeriennrFilter();    //Set filter 
        }
        else if (dgMaterial.SelectedColumn == dgMaterialLagerorte)
        {
            dgMaterialLagerorte.SearchFilter = GetLagerorteFilter();    //Set filter 
        }
    }       
    return result;
}
```

```csharp
public virtual string GetSeriennrFilter()
{
    var filter = "bestand > 0 AND seriennr.status <> 10";
    
    if (SelectedMaterialRow != null)
    {
        filter += string.Format(" AND seriennr.art_nr = '{0}' AND bestand_detail.lager_nr = {1}", SelectedMaterialRow.art_nr, SelectedMaterialRow.lager_nr);
    }
    
    return filter;
}
```

The following method can be found in wndTermin and it shows the IteamSearching approach for DataPanel Controls (xTextBoxSearch).

```csharp
public override bool ItemSearching(FrameworkElement sourceControl)
{
    if (sourceControl == tbsGPNr)    //DataPanel Control
    {
        var persTyp = _context.pers_typ ?? 0;
        if (persTyp != 0)
            tbsGPNr.SearchFilter = string.Format("perstyp = {0}", persTyp);
    }

    return base.ItemSearching(sourceControl);
}
```

## ItemSearched \[deprecated]

{% hint style="danger" %}
This no longer exists in v16+.

Please look at for the changes [ItemChanged](/documentation/framework/window-handling-object/itemchanging.md#itemchanged).

For SearchType="BrowseFile" functionality we now use the [xFileBrowse](/documentation/framework/controls/xfilebrowse-v16+.md) control.
{% endhint %}

At this point, the search-action has already taken place.

```csharp
public override void ItemSearched(FrameworkElement sourceControl, xSqlResult result)
{
    base.ItemSearched(sourceControl, result);
    
    var textBoxSearch = sourceControl as xTextBoxSearch;
    if (textBoxSearch == null) return;

    if (sourceControl.Name == dgMaterialSeriennr.Name)    //DataGrid Column 
    {
        SetSerriennr(textBoxSearch.ResultRow);    //Set filter 
    }            
    return result;
}
```

The following method can be found in wndTermin and it shows the IteamSearched approach for DataPanel Controls (xTextBoxSearch).

```csharp
public override void ItemSearched(FrameworkElement sourceControl, xSqlResult result)
{
    base.ItemSearched(sourceControl, result);
    
    xTextBoxSearch textBoxSearch = sourceControl as xTextBoxSearch;
    if (textBoxSearch == null) return;
    
    if (textBoxSearch == tbsSerienNrSearch)     //DataPanel Control 
    {
        OnSerienNrSearched(textBoxSearch);
        SelectSerienNrColumn();
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://tldocs.gitbook.io/documentation/framework/window-handling-object/itemsearching.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
