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

4 posts, 1 answers
  1. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 26 May 2010 Link to this post

    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]
  2. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 28 May 2010 Link to this post

    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 ?
  3. DevCraft banner
  4. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 28 May 2010 Link to this post

    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.
  5. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 31 May 2010 Link to this post

    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.
Back to Top