Hello,
I have the following requirements:
- When the user enters from outside the grid into the empty grid a new row should be created and the second cell should be selected in edit mode.
- When the user enters from outside the grid into a grid with existing rows, the second cell should be selected in edit mode.
I am using the enter-key to move to the next field in a particular viewmodel, instead of the tab-key.
How can I accomplish this, I tried searching a solution but couldnt find anything that accomplish this when entering the grid from outside?
Any help would be greatly appreciated.
Marcel
4 Answers, 1 is accepted
I will try to address both scenarios you have described.
First of all, you should check if the respective GridView has any items.
1) If the GridView is empty, you can call RadGridView's BeginInsert() method and then set the CurrentCell to the cell in the second column:
if
(
this
.RadGridView.Items.Count == 0)
{
this
.RadGridView.BeginInsert();
this
.RadGridView.CurrentCellInfo =
new
GridViewCellInfo(RadGridView.CurrentItem, RadGridView.Columns[1]);
}
2) If there are items in the GridView, you can select the second cell of the last item, for example, and call RadGridView's BeginEdit() method:
else
{
RadGridView.Items.MoveCurrentToLast();
this
.RadGridView.CurrentCellInfo =
new
GridViewCellInfo(RadGridView.CurrentItem, RadGridView.Columns[1]);
this
.RadGridView.BeginEdit();
}
It is up to you to pick the event on which you will trigger the respective operation. If you're navigating with the Enter key, for example, you can handle the window's PreviewKeyUp event like so:
public
MainWindow()
{
InitializeComponent();
this
.PreviewKeyUp += MainWindow_PreviewKeyUp;
}
void
MainWindow_PreviewKeyUp(
object
sender, KeyEventArgs e)
{
if
(e.Key == Key.Enter && FocusManager.GetFocusedElement(
this
) ==
this
.RadGridView)
{
HandleNavigation();
}
}
void
HandleNavigation()
{
if
(
this
.RadGridView.Items.Count == 0)
{
this
.RadGridView.BeginInsert();
this
.RadGridView.CurrentCellInfo =
new
GridViewCellInfo(RadGridView.CurrentItem, RadGridView.Columns[1]);
}
else
{
RadGridView.Items.MoveCurrentToLast();
this
.RadGridView.CurrentCellInfo =
new
GridViewCellInfo(RadGridView.CurrentItem, RadGridView.Columns[1]);
if
(
this
.RadGridView.CurrentCell.IsInEditMode)
{
this
.RadGridView.CommitEdit();
}
this
.RadGridView.BeginEdit();
}
}
I'm attaching a sample project to better illustrate this. Please let me know if this approach would work for you.
Regards,
Dilyan Traykov
Telerik

Hello Dilyan,
Thanks for the support, had to alter the example code a little bit but now its working!
Regards,
Marcel

hii i have added a radmulticolumcombobox as gridviewdatacolum cell template in RadGridView...but when i am trying to focus cell using Tab or enter key it does not focus directly on that multicombobox column.....how to solve this...could you please give me a solution for this ?
Regards,
<
telerik:GridViewDataColumn
Width
=
"300"
IsReadOnly
=
"True"
IsFilterable
=
"False"
IsGroupable
=
"False"
DataMemberBinding
=
"{Binding ourItemCode, Mode=TwoWay}"
CellStyle
=
"{StaticResource GridViewCellStyle}"
UniqueName
=
"ItemCode"
Header
=
"Item Code"
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
telerik:RadMultiColumnComboBox
telerik:StyleManager.Theme
=
"Summer"
BorderThickness
=
"0"
Width
=
"Auto"
Height
=
"Auto"
AutoCompleteMode
=
"SuggestAppend"
Tag
=
"{Binding product_Id,Source={StaticResource StatusList}}"
SelectedValuePath
=
"product_Id"
DropDownWidth
=
"400"
DisplayMemberPath
=
"product_code"
SelectedValue
=
"{Binding TempItemId,Mode=TwoWay}"
CloseDropDownAfterSelectionInput
=
"True"
OpenDropDownOnFocus
=
"True"
SelectionChanged
=
"RadMultiColumnComboBox_SelectionChanged"
KeyDown
=
"RadMultiColumnComboBox_KeyDown"
GotFocus
=
"RadMultiColumnComboBox_GotFocus"
LostFocus
=
"RadMultiColumnComboBox_LostFocus_1"
>
<
telerik:RadMultiColumnComboBox.ItemsSourceProvider
>
<
telerik:GridViewItemsSourceProvider
ItemsSource
=
"{StaticResource ItemCodeList}"
>
</
telerik:GridViewItemsSourceProvider
>
</
telerik:RadMultiColumnComboBox.ItemsSourceProvider
>
</
telerik:RadMultiColumnComboBox
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
Ranees Ras

hii i have added a radmulticolumcombobox as gridviewdatacolum cell template in RadGridView...but when i am trying to focus cell using Tab or enter key it does not focus directly on that multicombobox column.....how to solve this...could you please give me a solution for this ?
Regards,
Ranees Ras
<
telerik:GridViewDataColumn
Width
=
"300"
IsReadOnly
=
"True"
IsFilterable
=
"False"
IsGroupable
=
"False"
DataMemberBinding
=
"{Binding ourItemCode, Mode=TwoWay}"
CellStyle
=
"{StaticResource GridViewCellStyle}"
UniqueName
=
"ItemCode"
Header
=
"Item Code"
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
telerik:RadMultiColumnComboBox
telerik:StyleManager.Theme
=
"Summer"
BorderThickness
=
"0"
Width
=
"Auto"
Height
=
"Auto"
AutoCompleteMode
=
"SuggestAppend"
Tag
=
"{Binding product_Id,Source={StaticResource StatusList}}"
SelectedValuePath
=
"product_Id"
DropDownWidth
=
"400"
DisplayMemberPath
=
"product_code"
SelectedValue
=
"{Binding TempItemId,Mode=TwoWay}"
CloseDropDownAfterSelectionInput
=
"True"
OpenDropDownOnFocus
=
"True"
SelectionChanged
=
"RadMultiColumnComboBox_SelectionChanged"
KeyDown
=
"RadMultiColumnComboBox_KeyDown"
GotFocus
=
"RadMultiColumnComboBox_GotFocus"
LostFocus
=
"RadMultiColumnComboBox_LostFocus_1"
>
<
telerik:RadMultiColumnComboBox.ItemsSourceProvider
>
<
telerik:GridViewItemsSourceProvider
ItemsSource
=
"{StaticResource ItemCodeList}"
>
</
telerik:GridViewItemsSourceProvider
>
</
telerik:RadMultiColumnComboBox.ItemsSourceProvider
>
</
telerik:RadMultiColumnComboBox
>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>