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
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 >>
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.
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 ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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();
}
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 ?
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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.
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.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>