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
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.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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
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 ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
For now it's time for zzzz
Regards
Jim
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
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 ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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
>
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
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 >>