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

GridViewBoundColumnBase AutoCompleteBoxColumn handling events, howto

9 Answers 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 03 Oct 2011, 10:51 AM
I am trying to implement a autocompletebox in a grid column using GridViewBoundColumnBase

I don't know how to handle events, I assume it's something like the ???? below

 

 

 

Public Class AutoCompleteBoxColumn
    Inherits GridViewBoundColumnBase
   
    Public Overloads Overrides Function CreateCellEditElement(ByVal cell As GridViewCell, ByVal dataItem As Object) As FrameworkElement
  
        Me.BindingTarget = AutoCompleteBox.SelectedItemProperty
  
        Dim cellEditElement As AutoCompleteBox = New AutoCompleteBox()
  
        cellEditElement.SetBinding(AutoCompleteBox.SelectedItemProperty, CreateValueBinding())
        ??????cellEditElement.AddHandler(  gridAutoCompleteBox_Populating )
        Return (TryCast(cellEditElement, FrameworkElement))
    End Function
    Private Function CreateValueBinding() As System.Windows.Data.Binding
        Dim valueBinding As New System.Windows.Data.Binding()
        valueBinding.Mode = BindingMode.TwoWay
        valueBinding.NotifyOnValidationError = True
        valueBinding.ValidatesOnExceptions = True
        valueBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit
        valueBinding.Path = New PropertyPath(Me.DataMemberBinding.Path.Path)
        Return valueBinding
    End Function
End Class


Private Sub gridAutoCompleteBox_Populating(sender As System.Object, e As System.Windows.Controls.PopulatingEventArgs)
    'Access database here
    
e.Cancel = True
End Sub



Any ideas
Thanks
Jim

9 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 03 Oct 2011, 12:45 PM
Hello Jim,

I would recommend you to work directly with GridViewComboBoxColumn. Once you set its IsComboBoxEditable property to "True", the autocomplete functionality will be turned on by default.
Please take a look at our online documentation and demos for a reference.


Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jim
Top achievements
Rank 1
answered on 03 Oct 2011, 02:09 PM
I need the functionality of the autocomplete box.
I can get it working OK as a stand alone control.
I originally tried <DataTemplate> which nearly worked.
And then GridViewBoundColumnBase which again nearly worked.
I have difficulty accessing the itemsource and setting handlers once it's in the Grid
Thanks
Jim
0
Maya
Telerik team
answered on 03 Oct 2011, 04:09 PM
Hello Jim,

I am sending you a sample project illustrating how you can define an AutoComplteBox as a CellEditTemplate. You can add handlers directly to the element.
Will that work for you ? 

Best wishes,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jim
Top achievements
Rank 1
answered on 03 Oct 2011, 08:06 PM
Thanks I look forward to reading this in the morning.
For now it's time for zzzz
Regards
Jim
0
Jim
Top achievements
Rank 1
answered on 04 Oct 2011, 09:15 AM
Hello and thanks for the example , I am getting nearer.
1) I should have worked out how to capture events by just adding an attribute to the xaml. I was thrown by ...
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
2) I can get which AutoCompleteBox generating the populating event from the sender parameter, and thus set its Item.Source dynamically.

So my autocompletebox offers the drop down and the cell displays the selected value.
However when I move to a new row the data reverts to what was originally in the row.
I have tired below to no avail.
Jim
Private Sub gridAutoCompleteBox_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
      Dim selectedRoomType As Roomtype = DirectCast(e.AddedItems(0), Roomtype)
      Dim currentRowRoomType As Roomtype = DirectCast(RadGridView1.SelectedItem, Roomtype)

      RadGridView1.Items.EditItem(currentRowRoomType)

      currentRowRoomType = selectedRoomType
      RadGridView1.Items.CommitEdit()
      Dim x As Integer = 0
  End Sub


0
Maya
Telerik team
answered on 04 Oct 2011, 09:57 AM
Hello Jim,

How do you define your column - do you create your own custom one or you used the approach with having a CellEditTemplate ? Do you set the DataMemberBinding of the column ? Will it be possible to update the project I attached previously so that it reflects your scenario and let me know how do you change it  ? 

 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jim
Top achievements
Rank 1
answered on 04 Oct 2011, 11:24 AM
Grid xaml is ..
<
telerik:RadGridView AutoGenerateColumns="False" Grid.Row="1" HorizontalAlignment="Left" Name="RadGridView1" VerticalAlignment="Top" Grid.ColumnSpan="4" Height="282" Width="640" >
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn UniqueName="RoomTypeCode" DataMemberBinding="{Binding RoomTypeCode}" Header="Room Type Code">
            <telerik:GridViewDataColumn.CellEditTemplate>
                <DataTemplate>
                    <sdk:AutoCompleteBox  x:Name="jimsAutoCompleteBox" SelectionChanged ="gridAutoCompleteBox_SelectionChanged" Populating="gridAutoCompleteBox_Populating" VerticalAlignment="Top" ValueMemberPath="RoomTypeCode" Width="133" HorizontalAlignment="Left" Grid.ColumnSpan="2" MinimumPrefixLength="1" MinimumPopulateDelay="500">
                        <sdk:AutoCompleteBox.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding RoomTypeCode}" />
                                    <TextBlock Text=" : " />
                                    <TextBlock Text="{Binding Description}" />
                                </StackPanel>
                            </DataTemplate>
                        </sdk:AutoCompleteBox.ItemTemplate>
                    </sdk:AutoCompleteBox>
                </DataTemplate>
            </telerik:GridViewDataColumn.CellEditTemplate>
        </telerik:GridViewDataColumn>
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Description, Mode=TwoWay}" Header="Room Description"  Background="#FFEBEBEB" IsReadOnly="True"/>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>
0
Jim
Top achievements
Rank 1
answered on 04 Oct 2011, 11:36 AM
Hmm
Tried your supplied example again.
And whilst the AutoCompleteBox and drop down seem to work, it appears that the data does not go in the grid when you exit the cell
Or am I doing something wromg ?
Jim
0
Maya
Telerik team
answered on 05 Oct 2011, 08:22 AM
Hi Jim,

You are quite right. I missed to set just a single property in the CellEditTemplate definition. Please set the Mode property of Text Binding of AutoComplateBox:

<input:AutoCompleteBox Text="{Binding Name, Mode=TwoWay}"                                                 
                                                   ItemsSource="{Binding Players, Source={StaticResource MyViewModel}}" />

 

Best wishes,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Jim
Top achievements
Rank 1
Answers by
Maya
Telerik team
Jim
Top achievements
Rank 1
Share this question
or