Skip to content

Commit

Permalink
allow removing any column
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Miller committed Dec 27, 2023
1 parent 4f83a1c commit f32a47a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
6 changes: 2 additions & 4 deletions Maui.DataGrid.Sample/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
<CheckBox IsChecked="{Binding HeaderBordersVisible}" />
<Label Text="Header Borders Visible?" TextColor="White" Margin="0,0,5,0" VerticalOptions="Center" />
</HorizontalStackLayout>
<HorizontalStackLayout HeightRequest="50" Margin="0,0,15,0">
<Button Text="Remove Teams" Clicked="OnRemoveTeamColumn" />
</HorizontalStackLayout>
<HorizontalStackLayout HeightRequest="50" Margin="0,0,15,0">
<CheckBox IsChecked="{Binding WonColumnVisible}" />
<Label Text="Won Column" TextColor="White" Margin="0,0,5,0" VerticalOptions="Center" />
Expand All @@ -30,7 +27,8 @@
<Stepper Minimum="0" Maximum="100" Increment="10" Value="{Binding TeamColumnWidth}" />
<Label Text="Team Col Width" TextColor="White" Margin="0,0,5,0" VerticalOptions="Center" />
</HorizontalStackLayout>
<Button x:Name="_addColumnButton1" Text="Add Column" />
<Button Text="Remove Column" Clicked="OnRemoveColumn" />
<Button Text="Add Column" Clicked="OnAddColumn" />
</FlexLayout>

<dg:DataGrid Grid.Row="1" ItemsSource="{Binding Teams}" SelectionEnabled="True" SelectedItem="{Binding SelectedTeam}"
Expand Down
11 changes: 8 additions & 3 deletions Maui.DataGrid.Sample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ public MainPage()
{
InitializeComponent();
BindingContext = new MainViewModel();
_addColumnButton1.Clicked += OnAddColumn;
}

private void OnAddColumn(object sender, EventArgs e)
{
_dataGrid1.Columns.Add(new DataGridColumn() { Title = "Test", Width = new(100) });
}

private void OnRemoveTeamColumn(object sender, EventArgs e)
private async void OnRemoveColumn(object sender, EventArgs e)
{
var teamColumn = _dataGrid1.Columns.FirstOrDefault(c => c.Title == "Team");
var columnTitle = await Shell.Current.DisplayPromptAsync("Which column should be removed?", "Remove column");

var teamColumn = _dataGrid1.Columns.FirstOrDefault(c => c.Title == columnTitle);

if (teamColumn != null)
{
_ = _dataGrid1.Columns.Remove(teamColumn);
}
else
{
await Shell.Current.DisplayAlert("Column not found", "No column by that title", "Ok");
}
}
}

0 comments on commit f32a47a

Please sign in to comment.