Xamarin forms datagrid does not show related data
Ann Brady
1
Reputation point
I am trying to setup the following. A listview that shows a list of daily surgery cases. When a case is clicked it navigates to a content page containing the details for the case as well as a linked datagrid that contains all of the staff (caseStaffJoin) for the case. I am able to see the listview and navigate to the case detail. The problem is that the staff do not populate the datagrid using the sxCaseId. How do I get the datagrid to show the related staff.
public class SxCaseDetailViewModel :ViewModelBase
{
private ObservableCollection<CaseStaffJoin> _caseStaffJoins;
private ISxCaseDataService _sxCaseDataService;
private ICaseStaffJoinDataService _caseStaffJoinDataService;
private SxCase _selectedSxCase;
private CaseStaffJoin _selectedCaseStaffJoin;
public SxCaseDetailViewModel(IConnectionService connectionService,
INavigationService navigationService, IDialogService dialogService,
ICaseStaffJoinDataService caseStaffJoinDataService,
ISxCaseDataService sxCaseDataService)
: base(connectionService, navigationService, dialogService)
{
_sxCaseDataService = sxCaseDataService;
_caseStaffJoinDataService = caseStaffJoinDataService;
CaseStaffJoins= new ObservableCollection<CaseStaffJoin>();
}
public ObservableCollection<CaseStaffJoin> CaseStaffJoins
{
get => _caseStaffJoins;
set
{
_caseStaffJoins = value;
OnPropertyChanged();
}
}
public SxCase SelectedSxCase
{
get => _selectedSxCase;
set
{
_selectedSxCase = value;
OnPropertyChanged();
}
}
public CaseStaffJoin SelectedCaseStaffJoin
{
get => _selectedCaseStaffJoin;
set
{
_selectedCaseStaffJoin = value;
OnPropertyChanged();
}
}
private async Task GetCaseStaffJoins()
{
CaseStaffJoins = (ObservableCollection<CaseStaffJoin>)await _caseStaffJoinDataService.GetAllCaseStaffJoinsAsync();
}
public override async Task InitializeAsync(object data)
{
IsBusy = true;
SelectedSxCase = (SxCase)data;
IsBusy = false;
}
}
}
Page
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:utility="clr-namespace:QiX.Utility;assembly=QiX"
xmlns:renderers="clr-namespace:Syncfusion.SfDataGrid.XForms.Renderers;assembly=Syncfusion.SfDataGrid.XForms"
xmlns:xForms="clr-namespace:Syncfusion.SfDataGrid.XForms;assembly=Syncfusion.SfDataGrid.XForms"
x:Class="QiX.Views.SxCaseDetailView"
utility:ViewModelLocator.AutoWireViewModel="True"
Title="Details">
<ContentPage.Content>
<ScrollView>
<StackLayout>
<StackLayout Padding="10">
<Grid Grid.Row="0" Padding="10" x:Name="MasterGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Text="CaseId" Grid.Row="0" Grid.Column="0"/>
<Label Text="{Binding SelectedSxCase.SxCaseId}" Grid.Row="0" Grid.Column="1"/>
<Label Text="Dos" Grid.Row="1" Grid.Column="0"/>
<renderers:SfDatePicker x:Name="dos" BindingContext="{Binding SelectedSxCase.Dos}" Grid.Row="1" Grid.Column="1" HorizontalOptions="StartAndExpand"/>
<Label Text="Eye" Grid.Column="0" Grid.Row="2"/>
<Picker x:Name="EyePicker" ItemsSource="{Binding Eyes, Mode=TwoWay}"
ItemDisplayBinding="{Binding Eye1, Mode=TwoWay}"
SelectedItem="{Binding SelectedSxCase.EyeId, Mode=TwoWay}"
SelectedIndex="{Binding SelectedSxCase.EyeId, Mode=TwoWay}" Grid.Column="1" Grid.Row="2"/>
<Label Text="Facesheet" Grid.Column="0" Grid.Row="3"/>
<Entry Text="{Binding SelectedSxCase.Facesheet, Mode=TwoWay}" Grid.Column="1" Grid.Row="3"/>
<Label Text="Record" Grid.Column="0" Grid.Row="4"/>
<Entry Text="{Binding SelectedSxCase.Record, Mode=TwoWay}" Grid.Column="1" Grid.Row="4"/>
<Label Text="Complication" Grid.Column="0" Grid.Row="5"/>
<Switch IsToggled="{Binding SelectedSxCase.Complication, Mode=TwoWay}" Grid.Column="1" Grid.Row="5"/>
<Label Text="ReturnOr" Grid.Column="0" Grid.Row="6"/>
<Switch IsToggled="{Binding SelectedSxCase.ReturnOr, Mode=TwoWay}" Grid.Column="1" Grid.Row="6"/>
<Label Text="Physician" Grid.Column="0" Grid.Row="7"/>
<Picker x:Name="PhysicianPicker" ItemsSource="{Binding Physicians, Mode=TwoWay}"
ItemDisplayBinding="{Binding Physician1, Mode=TwoWay}"
SelectedItem="{Binding SelectedSxCase.PhysicianId, Mode=TwoWay}"
SelectedIndex="{Binding SelectedSxCase.PhysicianId, Mode=TwoWay}" Grid.Column="1" Grid.Row="7"/>
<Button Text="Update Case" Style="{StaticResource RegularButton}"
Command="{Binding UpdateSxCaseCommand}" Grid.Row="8" Grid.Column="0" Grid.ColumnSpan="2"
HorizontalOptions="Center"/>
<Button Text="Delete Case" Style="{StaticResource RegularButton}"
Command="{Binding DeleteSxCaseCommand}" Grid.Row="8" Grid.Column="1" Grid.ColumnSpan="2"
HorizontalOptions="Center"/>
</Grid>
</StackLayout>
<StackLayout>
<xForms:SfDataGrid
ItemsSource="{Binding CaseStaffJoins}"
DefaultColumnWidth="100">
</xForms:SfDataGrid>
</StackLayout>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
Sign in to answer