I am novice in WPF. I have a wpftoolkit datagrid where i am using a combo box as datagridcombox column. I am using a observable collection of Codes for binding the combo box. Below is the collection and its class...
#Region "Class & Coll"
Public Class CodesColl
Inherits ObservableCollection(Of Codes)
End Class
Public Class Codes
Private pCode As String
Private pDescription As String
Public Sub New()
pCode = String.Empty
pDescription = String.Empty
End Sub
#End Region
#Region "Property"
Public Property fldCode() As String
Get
Return pCode
End Get
Set(ByVal value As String)
pCode = value
End Set
End Property
Public Property fldDescription() As String
Get
Return pDescription
End Get
Set(ByVal value As String)
pDescription = value
End Set
End Property
#End Region
End Class
Now what i want achieve is that i need to bind the collection with dropdown in the grid.In my grid i have two columns in first column i have to display the code (fldCode) , and on the selection of the code the next column of the same row will get populated with its description (fldDescription).
My Xaml is something like this:
<wpfkit:DataGrid Margin="3" Style="{DynamicResource SimpleDataGrid}" FontWeight="Normal"
MaxHeight="100" ItemsSource="{Binding Source={StaticResource odpExistingCodesColl}}"
AutoGenerateColumns="False" Name="dgCodes" VerticalScrollBarVisibility="Visible" >
<wpfkit:DataGrid.Columns>
<wpfkit:DataGridTemplateColumn IsReadOnly="True">
<wpfkit:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Style="{DynamicResource SimpleImageDelete}"/>
</DataTemplate>
</wpfkit:DataGridTemplateColumn.CellTemplate>
</wpfkit:DataGridTemplateColumn>
<wpfkit:DataGridComboBoxColumn Header="Code"
DisplayMemberPath="fldCode"
SelectedValueBinding="{Binding fldCodes.fldCode}"
SelectedValuePath="fldCode"
SelectedItemBinding="{Binding fldCodeList}"
Width="100" x:Name="cbTCodes" >
<wpfkit:DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="IsSynchronizedWithCurrentItem" Value="False" />
<Setter Property ="ItemsSource" Value="{Binding Path=odpCodesColl}"/>
</Style>
</wpfkit:DataGridComboBoxColumn.ElementStyle>
<wpfkit:DataGridComboBoxColumn.EditingElementStyle >
<Style TargetType="ComboBox">
<Setter Property ="ItemsSource" Value="{Binding Path=odpCodesColl}"/>
<Setter Property ="IsDropDownOpen" Value="True"/>
</Style>
</wpfkit:DataGridComboBoxColumn.EditingElementStyle>
</wpfkit:DataGridComboBoxColumn>
<wpfkit:DataGridTextColumn Width="375" Header="Description" x:Name="tbTCodeDescription" />
</wpfkit:DataGrid.Columns>
</wpfkit:DataGrid>
odpExistingCodesColl here is another collection through which i am binding th开发者_运维百科e entire grid and is used for sending the code and its description to but i am facing following problems
- Unable to display the codes in dropdown.
- Somehow i manged to do so but it disappears after loosing focus from the combobox.
- Unable to retrive the description on its selection change as , i am unable to find the event too.
So you guys are requested to help me out asap.. any help will be highly appreciated.. Thanks in Advance Amit Ranjan
You can check on Vincent's blog for detail information about how to work with Wpf DataGrid(DataGridComboBoxColumn too).
精彩评论