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

Problems with inserting a new row

3 Answers 143 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 31 May 2011, 08:04 AM
I am using RadGrid to update records with quite a few columns.  Due to having so many columns, I have decided to use RowDetails with data templates that contain about 40 controls (mainly ComboBoxes, TextBlocks, and TextBoxes).  On the actual row, there are 8 columns.  I needed the user to be able to filter on values in several columns that would have been GridViewComboBoxes columns and filtering on numeric ID's would not work.  In order to avoid confusion, I have marked all of those columns as read only and the user is to only edit data in the RowDetails.  I have a Button in the cell template of the last column on the grid that is using RadViewCommands.Delete.  I also have two buttons outside of the grid for saving and canceling.  These are calling SubmitChanges and RejectChanges on the model.

Problem #1 - I cannot figure out how to set the focus after an add to the first Textbox in the RowDetails.  There is no visual indication that any control has focus after Add New Item is clicked.

Problem #2 - After clicking the Add New Item, the escape key does not work to get out of the row edit.  I have to click on a cell on the actual row (not row details) and then the escape key takes out out of the record.  After you have done this, the escape key works fine after clicking Add New again.  It just has the problem after the first escape until you have clicked on a row.

Problem #3 - The first time you click Add New Item, the button associated with the delete command is greyed out.  This is the desired effect.  All the other rows still have the button enabled.  Upon clicking on the row to get around problem #2, all of the delete buttons are now greyed out.  I would prefer to have all of the buttons greyed out when in insert or edit mode.  After hitting escape and adding another new row all of the buttons are still enabled until you start making changes to the record and then all delete buttons are greyed out.  I am not sure why there is an inconsistency.  Maybe solving problem #2 will solve this one.

Problem #4 - It is not always user friendly to use the escape key to get out of a row edit.  I have seen users try to click the Cancel button that is outside of the grid to try to get out of the row edit.  I tried to set the button to a CancelRowEdit command, but then the button is disabled when you are not editing a row.  I have tried to manually call the CancelRowEdit method, but that doesn't seem to work for cancelling an insert.  I have tried changing the value of ActionOnLostFocus but I just cannot get the results that I want.  I would like the button to have dual purposes:  #1, submit changes to the model and #2, cancel any edit or insert that is in progress.

Problem #5 - I am trying to enable and disable the save and cancel buttons based on if the user made any changes or not.  I have code that allows for manual control by setting a property on the entity or an automated method that checks HasChanges on the entity.  Unfortunately I have some fields that I have added to the model to store descriptions based on ID's that are in the database.  When I load up the data I have to populate those fields and that triggers the HasChanges.  While I look for a solution to that problem, I wanted to implement the manual method of setting the manual property on the entity.  Because all of the editing of data is being handled in the RowDetails, I am having difficulty finding an event to trigger when a change is made.  I would hate to have to add events to every single control I have in the RowDetails template.  Is there something else I can use?

Any help would be appreciated.

-Randy

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 03 Jun 2011, 12:47 PM
Hi Randy,

Sorry for the late answer, I've spot a bug related to you questions.
Generally editing with RowDetails is not supported by RadGridView out of the box. Indeed this is possible but you cannot rely on editing events both (on cell and on row level). In fact in the default case when edit an existing row only cell related events are not raised, since these events are raised based on the move of the current cell.
The problem comes from the fact that when new item is added via "Click here ...", current cell does not belong to the new row (when all columns are read only like in your case). So if you set CurrentCell appropriately you will get the desired result (Problem #1 and Problem #2). I'm pasting a sample code snippet that demonstrates this approach.

void radGridView_RowDetailsVisibilityChanged(object sender, GridViewRowDetailsEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                e.DetailsElement.ChildrenOfType<TextBox>()[0].Focus();
            }));
 
            if (e.Row is GridViewNewRow)
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    this.radGridView.CurrentCellInfo = new GridViewCellInfo(e.Row.DataContext, this.radGridView.Columns[this.radGridView.Columns.Count - 1]);
                }));
            }
        }


Problem #3 Answer: Here I've found a bug with our commands support. I've updated your Telerik points accordingly. This issue will be solved with the next latest internal build (next Monday 13 June).

Problem #4: Indeed ActionOnLostFocus property could help you. In order to enable the described functionality you should set ActionOnLostFocus to "None" in xaml and call radGridView.CancelEdit() on button click. Otherwise when you click on the button RadGridView has already lost focus and the specified action is taken.

Problem #5: You can use DomainContext.HasChanges property or RadDomainDataSource.HasChanges property.

Let me know if this doesn't help.

Regards,
Nedyalko Nikolov
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
0
Randy
Top achievements
Rank 1
answered on 04 Jun 2011, 11:45 PM
This worked great.  Thank you.
0
Nedyalko Nikolov
Telerik team
answered on 06 Jun 2011, 02:09 PM
Hello Randy,

Unfortunately we cannot fix the problem #3 for your case in RadGridView's code since this "fix" breaks the general case (when there is at least one editable column). However there is a very simple workaround just add a single line to the code snippet, which I sent you with my previous answer.

void radGridView_RowDetailsVisibilityChanged(object sender, GridViewRowDetailsEventArgs e)
        {
            Dispatcher.BeginInvoke(new Action(() =>
            {
                e.DetailsElement.ChildrenOfType<TextBox>()[0].Focus();
            }));
 
            if (e.Row is GridViewNewRow)
            {
                Dispatcher.BeginInvoke(new Action(() =>
                {
                    this.radGridView.CurrentCellInfo = new GridViewCellInfo(e.Row.DataContext, this.radGridView.Columns[this.radGridView.Columns.Count - 1]);
                    CommandManager.InvalidateRequerySuggested();
                }));
            }
        }

Sorry for the inconvenience caused.

Regards,
Nedyalko Nikolov
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
Randy
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Randy
Top achievements
Rank 1
Share this question
or