【发布时间】:2018-10-26 13:39:24
【问题描述】:
我的数据网格中有一个下拉列,组合框的选项存储在 tmfCNCComponentStatus_threed 表中。我的主表有一个名为 [Status] 的列,它对应于该表中的键列。
正确的状态 [描述] 显示在我的数据网格中每一行的组合框中,但是当用户更改选择时,数据库没有更新,即使一切看起来都正常工作。正如许多类似帖子中所见,我将“UpdateSourceTrigger”设置为 PropertyChanged,但仍然没有骰子。任何见解将不胜感激!
<CollectionViewSource x:Key="StatusItems"/>
<DataGridTemplateColumn x:Name="StatusColumn" Header="Status" Width="*" IsReadOnly="False">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock x:Name="cboStatus" Text="{Binding Path=Description}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox x:Name="StatusCombo" SelectedValuePath="CNCComponentStatusKey" DisplayMemberPath="Description" SelectedValue="{Binding Status, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Source={StaticResource StatusItems}}" IsEditable="True" IsSynchronizedWithCurrentItem="True"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
背后的代码:
Dim com As String = "SELECT tmfCNCComponent_threed.[CNCComponentKey]
,tmfCNCComponent_threed.[CompanyID]
,tmfCNCComponent_threed.[JobNumber]
,tmfCNCComponent_threed.[LogNumber]
,tmfCNCComponent_threed.[Customer]
,tmfCNCComponent_threed.[DueDate]
,tmfCNCComponent_threed.[JobLeader]
,tmfCNCComponent_threed.[CADProgrammer]
,tmfCNCComponent_threed.[Salesperson]
,tmfCNCComponent_threed.[CNCProgrammer]
,tmfCNCComponent_threed.[ComponentDescription]
,tmfCNCComponent_threed.[ComponentFilePath]
,tmfCNCComponent_threed.[Material]
,tmfCNCComponent_threed.[ComponentSizeX]
,tmfCNCComponent_threed.[ComponentSizeY]
,tmfCNCComponent_threed.[ComponentSizeZ]
,tmfCNCComponent_threed.[QuantityShown]
,tmfCNCComponent_threed.[QuantityMirror]
,tmfCNCComponent_threed.[UpdateTime]
,tmfCNCComponent_threed.[Status]
,tmfCNCComponent_threed.[ProgStarted]
,tmfCNCComponentStatus_threed.[Description]
FROM [test_3DimensionalDB].[dbo].[tmfCNCComponent_threed]
INNER JOIN tmfCNCComponentStatus_threed
ON tmfCNCComponent_threed.Status = tmfCNCComponentStatus_threed.CNCComponentStatusKey
WHERE [ComponentDescription] " & component & " 'trode%' AND [CompanyID]='" & company & "' AND [Status]" & status & "ORDER BY [UpdateTime] DESC"
Dim Adpt As New SqlDataAdapter(com, con)
con.Open()
Dim ds As New DataSet()
Adpt.Fill(ds, "dbo.tmfCNCComponent_threed")
dataGrid1.ItemsSource = ds.Tables("dbo.tmfCNCComponent_threed").DefaultView
con.Close()
con.Open()
Dim statusCVS As CollectionViewSource = FindResource("StatusItems")
Dim com2 As String = "SELECT * FROM tmfCNCComponentStatus_threed"
Dim AdptStatus As New SqlDataAdapter(com2, con)
AdptStatus.Fill(ds, "dbo.tmfCNCComponentStatus_threed")
Dim statusRows = ds.Tables("dbo.tmfCNCComponentStatus_threed").Rows
Dim statuses As New List(Of Object)
For Each row As DataRow In statusRows
statuses.Add(New With {
.Status = CInt(row("CNCComponentStatusKey")),
.Description = CStr(row("Description"))
})
Next
statusCVS.Source = statuses
con.Close()
RowCount()
searchBox.Clear()
感谢您的宝贵时间。
数据库:
这是昨天为让我明白这一点而提出的这个问题的第一部分: Part 1
【问题讨论】:
-
DataGridComboBoxColumn很难使用。坚持使用模板栏。您是否尝试过 PresentationTraceSources.TraceLevel=High 和 DebugView? -
我无法让您在另一篇文章中链接的调试器在我的 Windows 10 机器上正常工作。它根本不会显示任何调试信息:(
-
您尝试调试了吗?附加到进程?
-
顺便说一句,您正在对
StatusItems中的内容保密。除非你说出里面有什么,否则没有人可以帮助你。是收藏吗?收藏中有什么?对象还是数据行?属性或列的名称和类型是什么? -
我不明白我在隐藏什么?在上面的 xaml 中,您可以看到我声明了我的 collectionviewsource。在代码中,特别是你昨天帮助我创建的底部部分,你可以看到我在哪里用数据填充视图源
标签: wpf vb.net data-binding wpfdatagrid