【问题标题】:expand xamgrid item when item is entered in search menu在搜索菜单中输入项目时展开 xamgrid 项目
【发布时间】:2013-01-10 06:41:18
【问题描述】:

我创建了一个 XamGrid,其中我有一个三层层次结构。我在silverlight 4 中创建了它。我在xamgrid 上方有一个搜索文本框,它是一个自动完成框。当我从 AutocompleteBox 中选择一个项目并按下回车键时,我希望 Grid 中的该项目得到扩展。我怎样才能做到这一点?? 请建议.. 我的自动完成 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>

【问题讨论】:

    标签: c# silverlight-4.0 infragistics xamgrid


    【解决方案1】:

    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;
    }
    

    【讨论】:

      猜你喜欢
      • 2022-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多