This is a migrated thread and some comments may be shown as answers.

Column visibility when clicking [Click here to add new item]

3 Answers 58 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marc Roussel
Top achievements
Rank 2
Marc Roussel asked on 26 May 2010, 03:52 PM
Hi,

I have a grid in which I have 2 custom columns, a DELETE button and a STOP button.
These buttons are changed dinamiclly by code according to certain conditions.

but when I add a new row by clicking the [Click here to add new item] these 2 buttons appears and the user can click them but it's not possible at this time.

So the question is how do I make my buttons invisible when clicking on the button to add a new row ?
I tried in the event AddingNewDataItem(...) but in there the e object have nothing to help me.  I mean I tried with OwnerGridViewItemsControl but even the ParenRow is null or I tried also with ParentOfType<GridviewRow> without success.

So just to say that I really don't know how to make my buttons invisible hwne clicking on the [Click here to add new item]

3 Answers, 1 is accepted

Sort by
0
Marc Roussel
Top achievements
Rank 2
answered on 28 May 2010, 10:35 AM
I found myself the right event.

void rgvTest_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)  
{  
    e.Row.Cells[0].Visibility = System.Windows.Visibility.Collapsed;  
    e.Row.Cells[1].Visibility = System.Windows.Visibility.Collapsed;  
}  
 

Can someone confirm ?
0
Marc Roussel
Top achievements
Rank 2
answered on 28 May 2010, 10:42 AM
Ops, I just saw it's getting in this event each time I start editing a new cell.  That's not what I need.
More like a RowEditStarting event that will be triggered once but there's none.
0
Accepted
Veselin Vasilev
Telerik team
answered on 31 May 2010, 12:00 PM
Hi Marc Roussel,

Yes, the BeginningEdit is the right place to hide those cells. As you pointed out in that event it is not known whether you insert new item or update an old item. To overcome this you can additionally subscribe to the AddingNewDataItem event and raise a flag:

private void gridView_BeginningEdit(object sender, Telerik.Windows.Controls.GridViewBeginningEditRoutedEventArgs e)
{
    if (isInserting)
    {
        e.Row.Cells[0].Visibility = System.Windows.Visibility.Collapsed;
        e.Row.Cells[1].Visibility = System.Windows.Visibility.Collapsed;
        ((GridViewCell) e.Row.Cells[2]).IsInEditMode = true;
    }
    isInserting = false;
}
 
protected bool isInserting;
 
private void gridView_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
{
    isInserting = true;
}

Attached is a sample application. Hope it helps.


Best wishes,
Veskoni
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
GridView
Asked by
Marc Roussel
Top achievements
Rank 2
Answers by
Marc Roussel
Top achievements
Rank 2
Veselin Vasilev
Telerik team
Share this question
or