I am having a bear of a time trying to set the value of a GridViewComboBoxColumn via code. I have the BeginningEdit event, which I use to grab the value of the cell when editing starts. Then I check to see if the cell value is null or empty in the CellValidating event. I can detect that it is wrong. That part works fine. I cannot figure out how to set it to the previous value, if their entered value isn't valid.
(My end goal is that when the user clears the value and leaves the field, it replaces the null entry with the value the cell had when they entered it.)
Here is my GridViewComboBoxColumn code:
Here is my BeginningEdit event:
Here is my CellValidating event (you can see a few of my attempts to get the right thing):
(My end goal is that when the user clears the value and leaves the field, it replaces the null entry with the value the cell had when they entered it.)
Here is my GridViewComboBoxColumn code:
<telerik:RadGridView x:Name=
"rgvCorrectionDetails"
Width=
"1036"
MaxWidth=
"1036"
Margin=
"5"
HorizontalAlignment=
"Left"
AutoGenerateColumns=
"False"
CanUserDeleteRows=
"False"
CanUserInsertRows=
"False"
IsReadOnly=
"True"
ScrollViewer.VerticalScrollBarVisibility=
"Auto"
BeginningEdit=
"rgvCorrectionDetails_BeginningEdit"
SelectionMode=
"Extended"
CellValidating=
"rgvCorrectionDetails_CellValidating"
>
<telerik:RadGridView.Columns>
<telerik:GridViewComboBoxColumn UniqueName=
"rcbxGridHoursType"
DataMemberBinding=
"{Binding HoursTypeCode}"
DisplayMemberPath=
"DropDownEntry"
EditTriggers=
"CellClick"
Header=
"Hours Type"
IsComboBoxEditable=
"True"
IsReadOnlyBinding=
"{Binding IsRowReadOnly}"
SelectedValueMemberPath=
"EntryStringId"
TextSearch.TextPath=
"DropDownEntry"
EditorStyle=
"{Binding Source={StaticResource RadComboBoxStandard}}"
/>
</telerik:RadGridView.Columns>
</telerik:RadGridView>
Here is my BeginningEdit event:
private
void
rgvCorrectionDetails_BeginningEdit(
object
sender, GridViewBeginningEditRoutedEventArgs e)
{
var _Row = rgvCorrectionDetails.SelectedItem
as
HoursCorrectionDetail;
if
(_Row !=
null
)
{
if
(_Row.IsRowReadOnly)
{
e.Cancel =
true
;
}
else
{
// Row can be edited, so save off previous value
CurrentHoursTypeCode = _Row.HoursTypeCode;
CurrentHoursType = _Row.HoursType;
}
}
}
Here is my CellValidating event (you can see a few of my attempts to get the right thing):
private
void
rgvCorrectionDetails_CellValidating(
object
sender, GridViewCellValidatingEventArgs e)
{
if
(e.Cell.Column.UniqueName ==
"rcbxGridHoursType"
)
{
if
(JobCodes.Any(pEntry => pEntry.DropDownEntry == (String) e.NewValue))
{
// This is good
}
else
{
// This is bad, need to reset value
// ((GridViewComboBoxColumn) rgvCorrectionDetails.Columns["rcbxGridHoursType"]).SelectedValueMemberPath = CurrentHoursTypeCode;
// e.Cell.Value = CurrentHoursType;
}
}
}