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

How to set Focus on First Cell when adding new Row?

7 Answers 239 Views
GridView
This is a migrated thread and some comments may be shown as answers.
comgiu
Top achievements
Rank 2
comgiu asked on 05 Apr 2012, 08:46 AM
Hi,
in my application I have a GridView with two columns, both of them are in binding with two Properties marked as a Key into my Entity Object. When I add a new row the GridView create a new Row and sets the focus on the SECOND Cell instead of the first one which is my expected behavior. 

My question is: how to set the focus on the firs cell (instead of the second)?

In my code when I add a new Row I am handling AddingNewDataItem in order to create the new Entity and setting some default properties.

Thanks in advance,
Marzio.

7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 05 Apr 2012, 09:07 AM
Hello Giuliano,

You can handle AddingNewDataItem and set the CurrentColumn property of the grid:

private void clubsGrid_AddingNewDataItem(object sender, GridViewAddingNewEventArgs e)
        {
            this.clubsGrid.CurrentColumn = this.clubsGrid.Columns[0];
        }
 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
comgiu
Top achievements
Rank 2
answered on 05 Apr 2012, 09:24 AM
Thansk for the fast reply, however your suggestion doesn't work.

My GridView displays Key and Description columns (see below for details)

This is my AddingNewDataItem code where ManageNew() is responsible for creating CurrentItem:

        public void OnRowAddingItem(Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
        {
            ManageNew();
            e.NewObject = CurrentItem;
            GridView.CurrentColumn = GridView.Columns[0];
        }

This is what ManagedNew() does.
The wrong behaviour of selecting second row does not change even in case I remove Key and Descriptor = string.Empty:

            CurrentIten = new Combinata()
            {
                ConnectionString = ContextInformation.ConnectionString,
                Key = string.Empty,
                Description = string.Empty,
                IsNewEntity = true
            };

This is my Entity and MyBase class contains ConnectionString  and IsNewEntity properties.

    public class Combinata: MyBaseClass
    {
        [Key]
        [Required(AllowEmptyStrings=false, ErrorMessage=REQUIRED)]
        [StringLength(10, ErrorMessage=STRINGTOOLONG)]
        public String Key { get; set; }

        [Required(AllowEmptyStrings = false, ErrorMessage = REQUIRED)]
        [StringLength(1200, ErrorMessage = STRINGTOOLONG)]
        public String Description { get; set; }

...
    }

Moreover I also tryed the following way but it does not work:

        void GridView_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)
        {
            if (GridView.RowInEditMode != null)
                GridView.CurrentCellInfo = new GridViewCellInfo(e.Row.DataContext, GridView.Columns[0]);
        }

Thanks for your support.
Marzio.
0
Maya
Telerik team
answered on 05 Apr 2012, 10:04 AM
Hello Giuliano,

I have tested the case, but I was not able to get the behavior you reported. Could you take a look at the sample attached and let me know whether you can reproduce the issue on it ? Am I missing something ?  

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
comgiu
Top achievements
Rank 2
answered on 05 Apr 2012, 10:30 AM
The only difference I noticed between your working example and my application is that in my project the "Combinata" is an Entity provided by my RIA Services Class Libraries, instead your Club is not.

This is the SL Client Code generated by RIA Service, I am wondering if this will changes (in some way) the GridView Insert bheaviour?
Do you have an example of GridView having the ItemsSouce set to an ObservableCollection of RIA Entity where you can test wrong behaviour I am experiencing?

    public sealed class Combinata : Entity
    {
        public Combinata();


        [DataMember]
        public string ConnectionString { get; set; }
        [DataMember]
        public DateTime DateIns { get; set; }
        [DataMember]
        public DateTime DateMod { get; set; }
        [Required(ErrorMessage = "Parametro obbligatorio.")]
        [StringLength(1200, ErrorMessage = "Lunghezza non valida. La stringa immessa supera il numero di caratteri consentiti.")]
        [DataMember]
        public string Description { get; set; }
        [DataMember]
        public bool IsNewEntity { get; set; }
        [RoundtripOriginal]
        [StringLength(10, ErrorMessage = "Lunghezza non valida. La stringa immessa supera il numero di caratteri consentiti.")]
        [DataMember]
        [Editable(false, AllowInitialValue = true)]
        [Key]
        [Required(ErrorMessage = "Parametro obbligatorio.")]
        public string Key { get; set; }
        [DataMember]
        [StringLength(12, ErrorMessage = "Lunghezza non valida. La stringa immessa supera il numero di caratteri consentiti.")]
        public string UserIns { get; set; }
        [StringLength(12, ErrorMessage = "Lunghezza non valida. La stringa immessa supera il numero di caratteri consentiti.")]
        [DataMember]
        public string UserMod { get; set; }


        public override object GetIdentity();
    } 

0
Maya
Telerik team
answered on 05 Apr 2012, 04:40 PM
Hello Giuliano,

I have tested the case on the application (RadGridView-RDDS-AddingNewDataItem.zip) attached in this forum thread, but still I was not able to reproduce it. Could you give it a try as well ?  

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
comgiu
Top achievements
Rank 2
answered on 05 Apr 2012, 05:05 PM
Hi Maya,
with the following project you should be able to reproduce the problem I am experiencing.

Here the link (use File->Download for downloading it): https://docs.google.com/open?id=0B3Dqpv3BI2u3SUI4YzB5RE5UbmU3R3lyNi13OWl4dw 

Sorry for using my google documents account but the project size exceeded the 2MB limit...

thank you for your effort,
Marzio.



0
Maya
Telerik team
answered on 10 Apr 2012, 03:40 PM
Hello Guiliano,

After further investigation, we have discovered that the cause of the issue is hidden in the fact that the key property is marked as [Editable(false)]. Consequently, when the grid checks whether it can be edited or not it removes the focus for the corresponding cell.
Nevertheless, we will continue investigating the case and let you know once we could provide more details on the case. 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
comgiu
Top achievements
Rank 2
Answers by
Maya
Telerik team
comgiu
Top achievements
Rank 2
Share this question
or