Question

I have a winForm with a dataGridView containging members of a team. These members each have an assigned role and other properties that are listed in a column in the grid but for the purpose of what I want to achieve they are irrelevant. I've also added a bindingNavigator with add, edit and delete buttons.

What I would like to implement is that the edit/delete button should be disabled when I select a row containing a team member in a certain role (Key Account Manager and some others) and be enabled when the selected member has no such role.

So, how can I set this up? Is there an event for the current selected row or selecting a new row I can add my code to?

I'm thinking something along he lines of this pseudocode:

if (SelectedRow.DataboundObject.Role == "KEY_ACCOUNT_MANAGER") 
{
    bindingNavigatorChangeItem.Enabled() = false;
    bindingNavigatordeleteItem.Enabled() = false;
}
Was it helpful?

Solution

I finally figured this out and it's working perfectly. What I had to do was add some code to the SelectionChanged event on my DataGridView:

var member = teamRoleBindingSource.Current as TeamRole;

if (member != null && member.RoleCode == "KEY_ACCOUNT_MANAGER")
{
    bindingNavigatorDeleteItem.Enabled = false;
    bindingNavigatorChangeItem.Enabled = false;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top