I am using Radgridview for winforms. I have a grid view with three columns. First column is a text box column and the second and third are button columns. Name of the command buttons are Apply and Remove respectively. When the form is loaded for the first time, Apply button in each row should be visible and Remove button must be in hidden state . When clicked on the Apply button it should become invisible and the remove button curresponding to that row should become visible. I have written the login in RowFormatting event and uses a boolean variable to make sure that this particular functionality happens only for the first time, that is when the form is loaded.
private void rgvRulesList_RowFormatting(object sender, RowFormattingEventArgs e)
{
if (!_assignedRules && slNo == ruleCount - 1)
{
ShowOrHideGridButtons();
}
}
private
void ShowOrHideGridButtons()
{
Guid ruleId = Guid.Empty;
foreach (GridViewDataRowInfo dataRowInfo in rgvRulesList.Rows)
{
GridCommandCellElement gridViewCellApply = (GridCommandCellElement)dataRowInfo.Cells["Apply"].CellElement;
GridCommandCellElement gridViewCellRemove = (GridCommandCellElement)dataRowInfo.Cells["Remove"].CellElement;
if (gridViewCellApply == null || gridViewCellRemove == null)
{
continue;
}
RadButtonElement rbApply = (RadButtonElement)gridViewCellApply.Children[0];
RadButtonElement rbRemove = (RadButtonElement)gridViewCellRemove.Children[0];
ruleId =
new Guid(gridViewCellApply.Value.ToString());
foreach (EntityRulesMapping mapping in _entityRuleMappingList)
{
if (mapping.RuleId == ruleId)
{
rbApply.Visibility =
ElementVisibility.Hidden;
rbRemove.Visibility =
ElementVisibility.Visible;
break;
}
else
{
rbApply.Visibility =
ElementVisibility.Visible;
rbRemove.Visibility =
ElementVisibility.Hidden;
}
}
// end of inner for each
}
// end of outer for each
_assignedRules =
true;
}
But i could not arrive at the required solution. But when i click any of the button, this rowformatting works and the required result is achieved. I think this is because, the rowformatting event happens when some user interaction happens with the grid. Please help me on this.