How to enable entry in one column when clicking a button in another column of the same row in .NET MAUI DataGrid?
In .NET MAUI DataGrid, you can enable an entry in one column when clicking a button in another column of the same row by changing the EmployeeStatus property of the entry on the button click.
Refer to the below code example in which an Entry and a Button are loaded as column elements using DataGridTemplateColumn.
Behavior
<syncfusion:SfDataGrid ItemsSource="{Binding Employees}"
AutoGenerateColumnsMode="None"
ColumnWidthMode="Auto"
DefaultColumnWidth="155">
<syncfusion:SfDataGrid.Columns>
<syncfusion:DataGridTextColumn MappingName="IDNumber"
HeaderText="ID Number" />
<syncfusion:DataGridTemplateColumn MappingName="Employee ID">
<syncfusion:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Entry IsEnabled="{Binding EmployeeStatus}"
Text="{Binding EmployeeID}"
TextColor="Black" />
</DataTemplate>
</syncfusion:DataGridTemplateColumn.CellTemplate>
</syncfusion:DataGridTemplateColumn>
<syncfusion:DataGridTemplateColumn MappingName="Name">
<syncfusion:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Text="{Binding Name}"
TextColor="Black">
<Button.Behaviors>
<behaviors:DataGridBehavior />
</Button.Behaviors>
</Button>
</DataTemplate>
</syncfusion:DataGridTemplateColumn.CellTemplate>
</syncfusion:DataGridTemplateColumn>
</syncfusion:SfDataGrid.Columns>
</syncfusion:SfDataGrid>
Xaml.cs
The code below illustrates how to enable the EmployeeStatus property of an entry when the button on the same row is clicked.
protected override void OnAttachedTo(Button button)
{
base.OnAttachedTo(button);
button.Clicked += OnButtonClicked;
}
protected override void OnDetachingFrom(Button button)
{
base.OnDetachingFrom(button);
button.Clicked -= OnButtonClicked;
}
private void OnButtonClicked(object sender, EventArgs e)
{
var data = ((sender as Button).BindingContext as Employee);
data.EmployeeStatus = true;
}
Download the complete sample from GitHub
Conclusion
I hope you enjoyed learning how to enable entry in one column when clicking a button in another column of the same row in .NET MAUI DataGrid (SfDataGrid).
You can refer to our .NET MAUI DataGrid feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI DataGrid Documentation to understand how to present and manipulate data.
For current customers, check out our .NET MAUI components on the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to explore our .NET MAUI DataGrid and other .NET MAUI components.
Please let us know in the comments section if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac or feedback portal, or the feedback portal. We are always happy to assist you!