XAML
<sf:SfDataGrid x:Name="dataGrid2"
ItemsSource="{Binding CKTypeSelector}"
AllowEditing="True"
NavigationMode="Cell"
SelectedItem="{Binding selCKType}"
SelectionMode="Single"
EditTapAction="OnDoubleTap"
EditorSelectionBehavior="MoveLast"
AllowPullToRefresh="False"
LiveDataUpdateMode="AllowDataShaping"
GroupingMode="Multiple"
ColumnSizer="Star"
AutoGenerateColumns="False"
AllowSorting="True"
VerticalOptions="FillAndExpand"
HorizontalOptions="FillAndExpand"
>
<sf:SfDataGrid.Columns>
<sf:GridTextColumn HeaderText="{extensions:Translate lblName}"
MappingName="Name"
AllowEditing="False" />
<sf:GridTemplateColumn HeaderText="{extensions:Translate lblValue}"
MappingName="selControlKey_ID"
MinimumWidth="200">
<sf:GridTemplateColumn.CellTemplate>
<DataTemplate>
<sfACompl:SfAutoComplete x:Name="autoComplete"
DataSource="{Binding PickerControlKeys}"
DisplayMemberPath="Name"
SelectedValuePath="ID"
SelectedValue="{Binding ??????? selControlKey_ID ???????}"
MaximumSuggestion="5"
AutoCompleteMode="Suggest"
SuggestionMode="Contains"
HighlightedTextFontAttributes="Bold"
HighlightedTextColor="Red"
DropDownTextSize="10"
DropDownItemHeight="14"
TextSize="12"
LoadMoreText="{extensions:Translate lblLoadMore}"
NoResultsFoundText="{extensions:Translate lblNoResult}" />
</DataTemplate>
</sf:GridTemplateColumn.CellTemplate>
</sf:GridTemplateColumn>
</sf:SfDataGrid.Columns>
</sf:SfDataGrid>
ViewModel
public class AccControlKeyTypeSelector
{
public AccControlKeyTypeSelector() { }
public int ID { get; set; }
public string Name { get; set; }
public ICollection<PickerControlKeys> PickerControlKeys { get; set; }
public int selControlKey_ID { get; set; }
}
public class PickerControlKeys
{
public PickerControlKeys() { }
public int ID { get; set; }
public string Name { get; set; }
}
public class BudgetTypePageViewModel : BaseViewModel, IBudgetTypePageViewModel
{
private ObservableCollection<AccControlKeyTypeSelector> _cktypeselector = new ObservableCollection<AccControlKeyTypeSelector>();
private AccControlKeyTypeSelector _selcktype = new AccControlKeyTypeSelector();
public ObservableCollection<AccControlKeyTypeSelector> CKTypeSelector
{
get { return _cktypeselector; }
set
{
_cktypeselector = value;
OnPropertyChanged(nameof(CKTypeSelector));
}
}
public AccControlKeyTypeSelector selCKType
{
get { return _selcktype; }
set
{
_selcktype = value;
OnPropertyChanged(nameof(selCKType));
}
}
..........
}
public class CountryList
{
private ObservableCollection<string> countryNames;
public ObservableCollection<string> CountryNames
{
get { return countryNames; }
set
{
countryNames = value;
RaisePropertyChanged("CountryNames");
}
}
private string selectedCountry;
public string SelectedCountry
{
get { return selectedCountry; }
set{
selectedCountry = value;
RaisePropertyChanged("SelectedCountry");
}
}
}
>>>>>>>>>>>
private CountryList countryList;
public CountryList CountryList
{
get { return countryList; }
set {
countryList = value;
RaisePropertyChanged("CountryList");
}
}
>>>>>>>>>>>
<sfgrid:GridTemplateColumn MappingName="CountryList">
<sfgrid:GridTemplateColumn.CellTemplate>
<DataTemplate>
<auto:SfAutoComplete DataSource="{Binding CountryList.CountryNames}" SelectedItem="{Binding CountryList.SelectedCountry}" ></auto:SfAutoComplete>
</DataTemplate>
</sfgrid:GridTemplateColumn.CellTemplate>
</sfgrid:GridTemplateColumn> |
Hi David MarekThanks for contacting Syncfusion support.We have checked your query with “how to bind SelectedValue of sfAutoComplete inside sfDataGrid” and your requirement can be achieved by using complex properties, so that we can bind for both DataSource and SelectedItem property in SfAutoComplete control. We have prepared a sample for the sample. Please find the sample and code form below.
public class CountryList{private ObservableCollection<string> countryNames;public ObservableCollection<string> CountryNames{get { return countryNames; }set{countryNames = value;RaisePropertyChanged("CountryNames");}}private string selectedCountry;public string SelectedCountry{get { return selectedCountry; }set{selectedCountry = value;RaisePropertyChanged("SelectedCountry");}}}>>>>>>>>>>>private CountryList countryList;public CountryList CountryList{get { return countryList; }set {countryList = value;RaisePropertyChanged("CountryList");}}>>>>>>>>>>><sfgrid:GridTemplateColumn MappingName="CountryList"><sfgrid:GridTemplateColumn.CellTemplate><DataTemplate><auto:SfAutoComplete DataSource="{Binding CountryList.CountryNames}" SelectedItem="{Binding CountryList.SelectedCountry}" ></auto:SfAutoComplete></DataTemplate></sfgrid:GridTemplateColumn.CellTemplate></sfgrid:GridTemplateColumn>Sample Link: SfGird_AutoComplete
Please let us know if this helpful.RegardsVigneshkumar R
<sf:SfDataGrid x:Name="dataGrid2"
ItemsSource="{Binding Source={x:Reference page}, Path=BindingContext.CKTypeSelector}"
AllowEditing="True"
NavigationMode="Cell"
SelectionMode="Single"
EditTapAction="OnDoubleTap"
EditorSelectionBehavior="MoveLast"
LiveDataUpdateMode="AllowDataShaping"
ColumnSizer="Star"
AutoGenerateColumns="False"
>
<!--SelectedItem="{Binding Source={x:Reference page}, Path=BindingContext.selCKType}"-->
<sf:SfDataGrid.Columns>
<sf:GridTextColumn HeaderText="{extensions:Translate lblName}"
MappingName="Name"
AllowEditing="True" />
<sf:GridTemplateColumn HeaderText="{extensions:Translate lblValue}"
MappingName="ControlKeyList"
MinimumWidth="200">
<sf:GridTemplateColumn.CellTemplate>
<DataTemplate>
<sfACompl:SfAutoComplete x:Name="autoComplete"
DataSource="{Binding ControlKeyList.PickerControlKeys}"
SelectedItem="{Binding ControlKeyList.selControlKey}"
DisplayMemberPath="Name"
......
public class AccControlKeyTypeSelector : ObservableObject
{
public AccControlKeyTypeSelector() { }
private int _id;
private string _name;
private ControlKeyList _controlkeylist;
public int ID
{
get { return _id; }
set { _id = value; OnPropertyChanged(nameof(ID)); }
}
[StringLength(100)]
public string Name
{
get { return _name; }
set { _name = value; OnPropertyChanged(nameof(Name)); }
}
public ControlKeyList ControlKeyList
{
get { return _controlkeylist; }
set { _controlkeylist = value; OnPropertyChanged(nameof(ControlKeyList)); }
}
}
public class ControlKeyList : ObservableObject
{
public ControlKeyList() { }
private ObservableCollection<PickerControlKeys> _pickercontrolkeys;
private PickerControlKeys _selcontrolkey;
public ObservableCollection<PickerControlKeys> PickerControlKeys
{
get { return _pickercontrolkeys; }
set { _pickercontrolkeys = value; OnPropertyChanged(nameof(PickerControlKeys)); }
}
public PickerControlKeys selControlKey
{
get { return _selcontrolkey; }
set { _selcontrolkey = value; OnPropertyChanged(nameof(selControlKey)); }
}
}
public class PickerControlKeys : ObservableObject
{
public PickerControlKeys() { }
private int _ID;
private string _Name;
public int ID
{
get { return _ID; }
set { _ID = value; OnPropertyChanged(nameof(ID)); }
}
public string Name
{
get { return _Name; }
set { _Name = value; OnPropertyChanged(nameof(Name)); }
}
}
Hi David Marek,
Thanks for the response.
We could not reproduce the issue "SelectedItem of SfAutoComplete is not shown". We have used the sample which have been provided on our previous update with the (16.4.0.44) Syncfusion Nuget. The Selected item get viewed as expected as shown on the Image given below.
If the issue get reproduced at your end, please update us with the modified sample. This will be helpful for us to provide better solution on this.
Regards,Selva Kumar V.
Hi David,We have already fixed a similar issue "SelectedItem property does not bind properly to the item selected from drop down". This fix has been included on our latest (16.4.0.48) version. Could you please update our Essential studio version to latest (16.4.0.48) and let us know whether the same issue get reproduced at your end.This will be helpful for us to provide better solution on this.Note: The image which has been provided in your previous update was not able to viewed/downloaded from our end.Regards,Dhanasekar