Posted 9 July 2025, 4:52 pm EST - Updated 9 July 2025, 5:00 pm EST
Hello,
I have a C1FlexGrid in WPF 4.6.2 - 2024v1 (839). I am using ColumnValueConverters on some of my fields.
<c1:C1FlexGrid
x:Name="flexGrid"
AutoGenerateColumns="False"
HorizontalAlignment="Stretch"
CellEditEnded="flexGrid_CellEditEnded"
BeginningEdit="flexGrid_BeginningEdit"
>
<c1:C1FlexGrid.Columns>
<c1:Column Binding="{Binding fkProjectID}" Header="Project" ColumnName="colProject" />
<c1:Column Binding="{Binding fkSubProjectID}" Header="SubProject" ColumnName="colSubProject" />
</c1:C1FlexGrid.Columns>
</c1:C1FlexGrid>
Dim controller As New Controller
flexGrid.ItemsSource = controller.GetObjectDetails() ' pkObjectDetailID, fkProjectID, fkSubProjectID
Dim projectList = From row In controller.GetProjectList().AsEnumerable()
Select New With
{
.pkProjectID = row.Field(Of Integer)("pkProjectID"),
.ProjectName = row.Field(Of String)("ProjectName")
}
Dim subProjectList = From row In controller.GetSubProjectList().AsEnumerable()
Select New With
{
.pkSubProjectID = row.Field(Of Integer)("pkSubProjectID"),
.ProjectName = row.Field(Of String)("ProjectName")
}
flexGrid.Columns("colProject").ValueConverter = New ColumnValueConverter(projectList, "pkProjectID", "ProjectName")
flexGrid.Columns("colSubProject").ValueConverter = New ColumnValueConverter(subProjectList, "pkSubProjectID", "ProjectName")
I want the functionality of my drop-downs to be as follows:
1. When I select a new value of Project, I want the Sub-Project to be set to blank to force the user to enter a new value there.
2. I want the Combo Box to be restricted to Sub Projects of the selected Project, not all of them.
So far, my attempts at a solution was to set the binded item to DBNull inside of a CellEditEnded event of my FlexGrid. I tried setting to NULL, but it throws an error that I “Cannot set Column ‘fkSubProjectID’ to be null. Please use DBNull instead.”
Dim oOriginalValues As Object
Private Sub flexGrid_BeginningEdit(sender As C1FlexGrid, e As CellEditEventArgs)
oOriginalValues = New With
{
.fkProjectID = IIf(IsDBNull(sender.Rows(e.Row).DataItem.Item("fkProjectID")), Nothing, sender.Rows(e.Row).DataItem.Item("fkProjectID")),
.fkSubProjectID = IIf(IsDBNull(sender.Rows(e.Row).DataItem.Item("fkSubProjectID")), Nothing, sender.Rows(e.Row).DataItem.Item("fkSubProjectID"))
}
End Sub
Private Sub flexGrid_CellEditEnded(sender As C1FlexGrid, e As CellEditEventArgs)
With sender.Rows(e.Row).DataItem
If .Item("fkProjectID") <> oOriginalValues.fkProjectID Then
.Item("fkSubProjectID") = DBNull.Value
End If
End With
End Sub
However, because the value is DBNull instead of Null, whenever I select the blank cell and then click off without setting a value, the ColumnValueConverter class throws an exception saying “Value not found in converter dictionary.” and the application crashes.
I have a few questions regarding my requirements:
1. How would I access the C1FlexComboBox that gets created on the columns, if possible?
2. How can I assign a value to my sender.Rows(e.Row).DataItem.Item(“fkSubProjectID”) and still use ColumnValueConverters?