This is a migrated thread and some comments may be shown as answers.

RadAutoCompleteBox in RadGridView

1 Answer 368 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 11 Dec 2018, 03:43 PM

I have a RadGridView, in the first column is an AutoCompleteBox for searching articles in every row and the other GridViewDataColumn's get filled by the Information of the chosen article in the AutoCompleteBox.

I have build the RadGridView with AutoCompleteBox like this:

 

                        <telerik:RadGridView.Columns>
                            <telerik:GridViewDataColumn
                    x:Name="ArtikelNr"
                    Header="Artikel-/Materialsuche"
                    Width="Auto"
                    MinWidth="150"                                      
                    IsReadOnly="True"
                    IsGroupable="True"
                    IsFilterable="True">
                                <telerik:GridViewDataColumn.CellStyle>
                                    <Style TargetType="{x:Type telerik:GridViewCell}">
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="{x:Type telerik:GridViewCell}">
                                                    <telerik:RadAutoCompleteBox  x:Name="AutoCompleteBox_ArtikelNr" DropDownItemTemplate="{StaticResource                                                                            CustomAutoCompleteBoxItemTemplate1}"
                                                    ItemsSource="{Binding DataContext.ArtikelAuswahl, RelativeSource={RelativeSource AncestorType={x:Type                                                                                   telerik:RadGridView}}}"
                                                    SelectedItem="{Binding RadAutoCompleteBoxArtikel_SelectedItem, Mode=TwoWay}"
                                                    SelectionChanged="AutoCompleteBoxArtikel_SelectionChanged"
                                                    FilteringBehavior="{StaticResource ArtikelSucheFilteringBehavior}"
                                                    DisplayMemberPath="ArtikelNr"
                                                    TextSearchMode="Contains"
                                                    MaxDropDownHeight="400" 
                                                    DropDownWidth="1000"
                                                    WatermarkContent="Suche..."
                                                    HorizontalAlignment="Stretch"
                                                    AutoCompleteMode="Suggest"
                                                    SelectionMode="Single"/>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </telerik:GridViewDataColumn.CellStyle>
                            </telerik:GridViewDataColumn>

… 

I fill the Columns with Information I seleced in the AutoCompleteBox like this:

        private void AutoCompleteBoxArtikel_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                if (currentTabellenDaten != null)
                {
                    //int rowIndex = this.radGridView1.Items.IndexOf(this.radGridView1.SelectedItem);
                    //rowIndex = rowIndex + 1;
                    TabellenDaten geladeneTabellenDaten = new TabellenDaten();
                    bool ok = MainViewModel.TabellenDatenController.LoadTabellenDaten(((Artikel)e.AddedItems[0]).ArtikelNr, geladeneTabellenDaten);
                    currentTabellenDaten.ArtikelNr = geladeneTabellenDaten.ArtikelNr;
                    currentTabellenDaten.ArtikelBez1 = geladeneTabellenDaten.ArtikelBez1;
                    currentTabellenDaten = null;
                    this.radGridView1.CommitEdit();
                    geladeneTabellenDaten = null;
                }

}

My Problem is, that I can't get the Row index of the Current edited AutoCompleteBox(I tried like in the Code commented out but doesn't work), so when I want to edit a Row that already has some Information (selecting an other article in the AutoCompleteBox) , the new Information should be written in the same Row.

 

Is it possible with my type of implemetation of the AutoCompleteBox in the RadGridView?

Is there an other or better way to have an AutoCompleteBox in the RadGridview?

 

I hope you can understand my Problem and I'm sorry for my bad english skills.

 

1 Answer, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 14 Dec 2018, 10:42 AM
Hello David,

You can get ahold of the index of the row which was edited by using the ParentOfType extension method on the RadAutoCompleteBox. Here's how you can do so in the AutoCompleteBoxArtikel_SelectionChanged method:

var acb = sender as RadAutoCompleteBox;
var row = acb.ParentOfType<GridViewRow>();
var item = row.DataContext;
var rowIndex = row.GridViewDataControl.Items.IndexOf(item);

On a side note, please have in mind that the recommended approach for specifying a custom template for the cells is via the column's CellTemplate property:

<telerik:GridViewDataColumn.CellTemplate>
    <DataTemplate>
        <telerik:RadAutoCompleteBox  x:Name="AutoCompleteBox_ArtikelNr" ... />
    </DataTemplate>
</telerik:GridViewDataColumn.CellTemplate>

I hope you find this helpful. Please let me know if the aforementioned approach for getting the row index works for you.

Regards,
Dilyan Traykov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
AutoCompleteBox
Asked by
David
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Share this question
or