Sorry if this is a dumb question I'm brand new to SyncFusion and its controls. So basically I have a DataGrid and in one of the columns I want to have either a Combo Box or an Auto Complete in there which should be bound to an ObservableCollection/List.
This is the code I have atm. I have two View Models one is for the Page (ShiftTemplatePageViewModel)and is for the individual items in the list itself (ShiftTemplateViewModel). When it runs it shows no items in the combo box
public sealed partial class ShiftTemplatePage : Page
{
public ShiftTemplatePageViewModel ViewModel { get; set; }
}
public partial class ShiftTemplatePageViewModel : BaseViewModel
{
private ShiftTemplateService ShiftTemplateService { get; set; }
private WorkerService WorkerService { get; set; }
}
public partial class ShiftTemplateViewModel: DataViewModel
{
[ObservableProperty]
private string _id;
[ObservableProperty]
private string? _name;
[ObservableProperty]
private Worker _worker;
[ObservableProperty]
private Client _client;
public ShiftTemplateViewModel()
{
Id = Guid.NewGuid().ToString();
}
}
public ObservableCollection<ShiftTemplateViewModel> ShiftTemplates;
public ObservableCollection<WorkerViewModel> Workers;
public ObservableCollection<ClientViewModel> Clients;
public ShiftTemplatePageViewModel()
{
ShiftTemplates = new ObservableCollection<ShiftTemplateViewModel>();
Workers = new ObservableCollection<WorkerViewModel>();
Clients = new ObservableCollection<ClientViewModel>();
ShiftTemplateService = new ShiftTemplateService(new RosterDBContext());
WorkerService = new WorkerService(new RosterDBContext());
}
}
ShiftTemplatePage:
<dataGrid:SfDataGrid
x:Name="shiftTemplatesDataGrid"
Grid.Row="2"
Grid.ColumnSpan="2"
AddNewRowPosition="Top"
AllowEditing="True"
AutoGenerateColumns="False"
ItemsSource="{Binding Path=ShiftTemplates}">
<dataGrid:SfDataGrid.Columns>
<dataGrid:GridTextColumn HeaderText="Name" MappingName="ShiftTemplates.Name" />
<dataGrid:GridTemplateColumn MappingName="ShiftTemplates.Worker.FullName">
<dataGrid:GridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Worker.FullName}" />
</DataTemplate>
</dataGrid:GridTemplateColumn.CellTemplate>
<dataGrid:GridTemplateColumn.EditTemplate>
<DataTemplate>
<ComboBox
DataContext="ShiftTemplateViewModel"
DisplayMemberPath="Name"
IsEditable="True"
ItemsSource="{Binding Path=Workers}"
SelectedValuePath="Name"
Text="{Binding FullName, Mode=TwoWay}" />
<!--
<Grid>
<editors:SfAutoComplete
x:Name="autoComplete"
Width="250"
DataContext="ShiftTemplateViewModel"
DisplayMemberPath="Worker.FullName"
ItemsSource="{Binding ViewModel.Workers}"
TextMemberPath="Worker.FullName" />
</Grid>
-->
</DataTemplate>
</dataGrid:GridTemplateColumn.EditTemplate>
</dataGrid:GridTemplateColumn>
</dataGrid:SfDataGrid.Columns>
</dataGrid:SfDataGrid>
Sorry for the late reply. Thanks very much Rabina that example of yours solved my issue :)
BTW I think it would be a good idea if more of these examples were posted somewhere on the site for others to also read.