Hello,
I am constructing something that we call a "fully editable grid". The basic idea behind this grid is that the user can do data entry into the grid as seamlessly as possible. The general workflow is that, once we have loaded in our ItemsSource, we use BeginInsert() to give the user a new row to start typing in. We trap the RowLoaded event to automatically put the first editable column of the inserted row in edit mode. The user can then type in and tab through the columns to the end.
We have both cell and row validation. We then trap the RowEditEnd event (which only fires after everything has validated) to do a BeginInsert() to give them another new row.
This is working extremely well except for one major problem: When the grid is wide enough that it needs to scroll, I can't get it to scroll back to the first column when inserting the new row. My code is currently putting the right cell in edit mode, but calling ScrollintoView isn't doing anything, and ScrollintoViewAsync is coming back into the "failed" callback. I've got both column and row virtualization turned off, and I'm kind of at my wits end on this one.
Here's some code snippets, so maybe you can figure out where my bad setting is, or what else I need to do to make this work.
Any help you can give me will be appreciated!
--Christina
I am constructing something that we call a "fully editable grid". The basic idea behind this grid is that the user can do data entry into the grid as seamlessly as possible. The general workflow is that, once we have loaded in our ItemsSource, we use BeginInsert() to give the user a new row to start typing in. We trap the RowLoaded event to automatically put the first editable column of the inserted row in edit mode. The user can then type in and tab through the columns to the end.
We have both cell and row validation. We then trap the RowEditEnd event (which only fires after everything has validated) to do a BeginInsert() to give them another new row.
This is working extremely well except for one major problem: When the grid is wide enough that it needs to scroll, I can't get it to scroll back to the first column when inserting the new row. My code is currently putting the right cell in edit mode, but calling ScrollintoView isn't doing anything, and ScrollintoViewAsync is coming back into the "failed" callback. I've got both column and row virtualization turned off, and I'm kind of at my wits end on this one.
Here's some code snippets, so maybe you can figure out where my bad setting is, or what else I need to do to make this work.
<
telerik:RadGridView
x:Name
=
"grdFiles"
SelectionMode
=
"Extended"
telerik:StyleManager.Theme
=
"{StaticResource MPTheme}"
ItemsSource
=
"{Binding JournalItemView}"
AutoGenerateColumns
=
"false"
Grid.Row
=
"1"
CanUserFreezeColumns
=
"false"
RowHeight
=
"20"
CanUserReorderColumns
=
"False"
RowIndicatorVisibility
=
"Visible"
CanUserResizeColumns
=
"True"
CanUserSortColumns
=
"True"
CanUserDeleteRows
=
"{Binding CanEdit}"
CanUserInsertRows
=
"{Binding CanEdit}"
ShowGroupPanel
=
"False"
IsFilteringAllowed
=
"False"
ShowColumnFooters
=
"True"
RowEditEnded
=
"grdFiles_RowEditEnded"
AddingNewDataItem
=
"grdFiles_AddingNewDataItem"
RowLoaded
=
"grdFiles_RowLoaded"
ValidatesOnDataErrors
=
"InEditMode"
RowValidating
=
"grdFiles_RowValidating"
ScrollMode
=
"RealTime"
EnableColumnVirtualization
=
"false"
EnableRowVirtualization
=
"False"
Height
=
"470"
CurrentCellChanged
=
"grdFiles_CurrentCellChanged"
IsReadOnly
=
"{Binding CanEdit, Converter={StaticResource NotConverter}}"
ElementExporting
=
"grdFiles_ElementExporting"
Deleted
=
"grdFiles_Deleted"
ColumnWidthChanged
=
"grdFiles_ColumnWidthChanged"
FrozenColumnCount
=
"1"
ActionOnLostFocus
=
"None"
SelectionUnit
=
"FullRow"
CanUserSelect
=
"False"
IsSynchronizedWithCurrentItem
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewSelectColumn
UniqueName
=
"SelectColumn"
/>
---6 editable grid columns---
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
private
void
ViewModel_Populated(
object
sender, EventArgs e)
{
grdFiles.BeginInsert();
}
private
void
grdFiles_AddingNewDataItem(
object
sender, GridViewAddingNewEventArgs e)
{
e.NewObject = ViewModel.NewObject();
}
private
void
grdFiles_RowLoaded(
object
sender, RowLoadedEventArgs e)
{
if
(e.Row
is
GridViewRow)
{
if
(e.Row.IsCurrent)
{
grdFiles.CurrentColumn = grdFiles.Columns[1];
(e.Row
as
GridViewRow).BeginEdit();
grdFiles.ScrollIntoView(e.Row.Item, grdFiles.Columns[1]);
//Doesn't work
}
}
}
private
void
grdFiles_RowEditEnded(
object
sender, Telerik.Windows.Controls.GridViewRowEditEndedEventArgs e)
{
int
rowIdx = grdFiles.Items.Cast<ValidatingJournalItem>().ToList().IndexOf(e.Row.Item
as
ValidatingJournalItem);
if
(e.EditAction != GridViewEditAction.Cancel)
{
if
(rowIdx + 1 == grdFiles.Items.Count && BaseViewModel.HasItemChanged(e.NewData, e.OldValues))
{
grdFiles.BeginInsert();
//Start new row if data was entered
}
else
if
(rowIdx + 1 == grdFiles.Items.Count)
{
grdFiles.CurrentColumn = grdFiles.Columns[1];
//Go back to first column if nothing was changed
grdFiles.ScrollIntoView(e.Row.Item, grdFiles.Columns[1]);
//doesn't work.
}
}
}
Any help you can give me will be appreciated!
--Christina