diff --git a/Maui.DataGrid.Sample/MainPage.xaml.cs b/Maui.DataGrid.Sample/MainPage.xaml.cs index a109d82..3b69feb 100644 --- a/Maui.DataGrid.Sample/MainPage.xaml.cs +++ b/Maui.DataGrid.Sample/MainPage.xaml.cs @@ -11,24 +11,33 @@ public MainPage() BindingContext = new MainViewModel(); } - private void OnAddColumn(object sender, EventArgs e) + private async void OnAddColumn(object sender, EventArgs e) { - _dataGrid1.Columns.Add(new DataGridColumn() { Title = "Test", Width = new(100) }); + var newColumnTitle = await Shell.Current.DisplayPromptAsync("Add column", "What is the name of the new column?"); + + if (string.IsNullOrEmpty(newColumnTitle)) + { + await Shell.Current.DisplayAlert("Title required", "A title is required in order to add a column.", "Ok"); + } + else + { + _dataGrid1.Columns.Add(new DataGridColumn() { Title = newColumnTitle, Width = new(100) }); + } } private async void OnRemoveColumn(object sender, EventArgs e) { - var columnTitle = await Shell.Current.DisplayPromptAsync("Which column should be removed?", "Remove column"); + var columnTitle = await Shell.Current.DisplayPromptAsync("Remove column", "Which column should be removed?"); - var teamColumn = _dataGrid1.Columns.FirstOrDefault(c => c.Title == columnTitle); + var columnToRemove = _dataGrid1.Columns.FirstOrDefault(c => c.Title == columnTitle); - if (teamColumn != null) + if (columnToRemove == null) { - _ = _dataGrid1.Columns.Remove(teamColumn); + await Shell.Current.DisplayAlert("Column not found", "No column by that title", "Ok"); } else { - await Shell.Current.DisplayAlert("Column not found", "No column by that title", "Ok"); + _ = _dataGrid1.Columns.Remove(columnToRemove); } } }