C# 在搜索菜单中输入项时展开xamgrid项

C# 在搜索菜单中输入项时展开xamgrid项,c#,silverlight-4.0,infragistics,xamgrid,C#,Silverlight 4.0,Infragistics,Xamgrid,我已经创建了一个XamGrid,其中有一个三级层次结构。我已经在silverlight 4中创建了它。我在xamgrid上方有一个搜索文本框,它是一个自动完成框。当我从自动完成框中选择一个项目并按enter键时,我希望网格中的该项目得到扩展。我该怎么做?? 请建议。。我的自动完成bos是: <local:ExtendedAutoCompleteBox x:Name="InvNamesSearch"

我已经创建了一个XamGrid,其中有一个三级层次结构。我已经在silverlight 4中创建了它。我在xamgrid上方有一个搜索文本框,它是一个自动完成框。当我从自动完成框中选择一个项目并按enter键时,我希望网格中的该项目得到扩展。我该怎么做?? 请建议。。我的自动完成bos是:

<local:ExtendedAutoCompleteBox
                            x:Name="InvNamesSearch"
                            WaterMark="TypeName"
                            HorizontalAlignment="Left" VerticalAlignment="Center" 
                            Width="300" Margin="5,0,0,0"
                            MinimumPrefixLength="3"   
                            IsTextCompletionEnabled="False"
                            Text="{Binding InvestmentText, Mode=TwoWay}"
                            ItemsSource="{Binding A,Mode=OneWay}"
                            SelectedItem="{Binding Path=B, Mode=TwoWay}"                                                
                            ValueMemberBinding="{Binding A}"                            
                            FilterMode="Contains" Canvas.Left="683" Canvas.Top="9"
                            Command="{Binding AutoSuggestEnterCommand}">
                    <local:ExtendedAutoCompleteBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock x:Name="txtAutoSelectedItem" Text="{Binding A}"  />
                        </DataTemplate>
                    </local:ExtendedAutoCompleteBox.ItemTemplate>
                </local:ExtendedAutoCompleteBox>

XamGrid有一个Rows属性,它是所有根级别行的集合。您可以遍历这些行及其子行,查找在“自动完成”框中搜索的数据。找到数据后,可以在相应行上将IsExpanded属性设置为true。代码可能如下所示:

// This function returns a row that contains the supplied search criteria
public Row FindRowFromAutoCompleteBox(RowCollection rootRows, string searchCriteria)
{
    foreach (Row row in rootRows)
    {
        if (row.Data is LevelOneDataType)
        {
            if ((row.Data as LevelOneDataType).LevelOneProperty == searchCriteria)
                return row;
        }
        if (row.Data is LevelTwoDataType)
        {
            if ((row.Data as LevelTwoDataType).LevelTwoProperty == searchCriteria)
                return row;
        }
        if (row.Data is LevelThreeDataType)
        {
            if ((row.Data as LevelThreeDataType).LevelThreeProperty == searchCriteria)
                return row;
        }
        // Search child rows.
        if (row.ChildBands.Count != 0)
        {
            Row result = FindRowFromAutoCompleteBox(row.ChildBands[0].Rows, searchCriteria);
            if (result != null)
                return result;
        }
    }

    return null;
}

// Walks up the hierarchy starting at the supplied row and expands parent rows as it goes.
public void ExpandHierarchy(Row row)
{
    Row parentRow = null;

    // The row is a child of another row.
    if (row.ParentRow is ChildBand)
        parentRow = (row.ParentRow as ChildBand).ParentRow;

    while (parentRow != null)
    {
        // Expand the row.
        parentRow.IsExpanded = true;

        if (parentRow.ParentRow is ChildBand)
            parentRow = (parentRow.ParentRow as ChildBand).ParentRow;
        else
            parentRow = null;
    }
}
使用这些函数,您现在可以搜索并展开到所需的行

Row result = FindRowFromAutoCompleteBox(xamGrid1.Rows, "Value");
if (result != null)
{
    ExpandHierarchy(result);
    result.IsSelected = true;
}