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

CurrentCell is always null

6 Answers 511 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 17 Jan 2011, 05:17 PM
Following an example at http://www.telerik.com/help/wpf/gridview-how-to-set-current-cell.html, I set the current cell in my grid with the following:
mainGrid.CurrentCellInfo = new GridViewCellInfo(myObj, mainGrid.Columns["Description"]);
mainGrid.Focus();
I can verify that CurrentCellInfo has been properly set, however CurrentCell is always null.  I'm trying to edit it programatically afterwards with:
mainGrid.CurrentCell.BeginEdit();
What could be wrong here?

6 Answers, 1 is accepted

Sort by
0
Brian
Top achievements
Rank 1
answered on 18 Jan 2011, 03:30 PM
I edited on the RowEditEnded.  In the CellEditEnding of another column, I set the collection value so they stay sync'd...


private void groupGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
       {
           e.Row.Cells[5].Content = ((GroupTask)groupGrid.SelectedItem).ElapsedTime;
       }
0
Maya
Telerik team
answered on 20 Jan 2011, 06:22 PM
Hello Paul,

We will investigate the issue you reported. For the time being you may use a Dispatcher for example:

void playersGrid_DataLoaded(object sender, EventArgs e)
{
            this.Dispatcher.BeginInvoke(new Action(() => this.playersGrid.CurrentCellInfo = new GridViewCellInfo(this.playersGrid.Items[5], this.playersGrid.Columns[3])));                
            this.playersGrid.Focus();
}

However, if you share more details about your requirements, I may be able to provide you with a more appropriate workaround.

All the best,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Paul
Top achievements
Rank 1
answered on 21 Jan 2011, 04:39 PM
Thanks for the response, but the dispatcher behaves the same way.  CurrentCell is always null.  The new line is added to the grid, but is supposed to be in an edit mode for the user to type in it.  I've tried with selecting a column via ordinal position, as well as text.  I also tried the dispatcher.  Here's the exact code:

         // Create a new item first
         TaskListClass t = new TaskListClass()
         {
            ID = -1,
            Completed = false,
            CompletedDate = new DateTime(1899, 12, 30),
            cType = 'C',
            Description = string.Empty,
            HID = iHID,
            SortOrder = (((TrackerObjClass)this.DataContext).TaskListVM.TaskList.Count == 0 ?
                         ((TrackerObjClass)this.DataContext).TaskListVM.TaskList.Max(ti => ti.SortOrder) + 1 :
                         0),
            UserID = App.UserID,
            GroupID = -1,
            DefaultID = -1                        
         };

         // Now, add it to the grid at the bottom
         ((TrackerObjClass)this.DataContext).TaskListVM.TaskList.Add(t);

         // Update the bindings for the grid to show it
         mainGrid.ItemsSource = from i in ((TrackerObjClass)this.DataContext).TaskListVM.TaskList
                                where ((i.cType == 'I') && (cbShowInsuranceTasks.IsChecked == true)) ||
                                      ((i.cType == 'J') && (cbShowJobTasks.IsChecked == true)) ||
                                      ((i.cType == 'C') && ((cbShowCustomTasks.IsChecked == true) || (i.ID == -1)))
                                orderby i.SortOrder
                                select i;   

         // Next, focus on it
         mainGrid.CurrentCellInfo = new GridViewCellInfo(t, mainGrid.Columns["Description"]);
         mainGrid.Focus();

         // Allow the user to put in any description
         if (mainGrid.CurrentCell != null) // ALWAYS NULL HERE?!?
         {
            mainGrid.CurrentCell.BeginEdit();
         }
0
Maya
Telerik team
answered on 24 Jan 2011, 03:08 PM
Hello Paul,

I have retested the issue and everything seems to work fine when using a Dispatcher. I am sending you a sample project for a reference.
Let me know in case of any misunderstandings according to your requirements. 

Greetings,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Paul
Top achievements
Rank 1
answered on 27 Jan 2011, 05:45 PM
Thank you for the example, but it did not work either.  I simply added a call to CurrentCell.BeginEdit() which failed.  I even tried it though an invoke call.

Finally I found a way to do it:  I started calling Grid.BeginEdit() rather than Grid.CurrentCell.BeginEdit().  CurrentCell is still always null.
0
Maya
Telerik team
answered on 28 Jan 2011, 11:28 AM
Hello Paul,

I have extended the code for the DataLoaded event as follows:

private void clubsGrid_DataLoaded(object sender, EventArgs e)
        {  
            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                this.clubsGrid.CurrentCellInfo = new GridViewCellInfo(this.clubsGrid.Items[2], this.clubsGrid.Columns[1]);
                this.clubsGrid.CurrentCell.IsInEditMode = true;
                //or
                //this.clubsGrid.CurrentCell.BeginEdit();
 
            }));
            this.clubsGrid.Focus();
        }

and everything works as expected - the CurrentCell is not null and it goes into edit-mode. Is there any misunderstandings according to the way you are getting the CurrentCell ?
Still, I am happy to see that you found the appropriate solution for you scenario. Let me know if you need any further assistance.
 

Best wishes,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Brian
Top achievements
Rank 1
Maya
Telerik team
Paul
Top achievements
Rank 1
Share this question
or