Getting values in a DataGridComboboxColumn from WPF DataGrid?

Posted by Peermohamedmydeen under WPF on 11/8/2010 | Points: 10 | Views : 24616 | Status : [Member] | Replies : 1
Hi All,

Am working with a WPF DataGrid. Am having 2 DataGridComboboxColumn in which User will select any one of the item.
But I could not able to bring the value of DataGridComboboxColumn in the dataGrid.ItemSource. How can I get the selected items values too?
The XAML:

<UserControl.Resources>
<col:ArrayList x:Key="ShiftKey">
<sys:String>Alt</sys:String>
<sys:String>Ctrl</sys:String>
<sys:String>Shift</sys:String>
</col:ArrayList>
</UserControl.Resources>

<DataGrid AutoGenerateColumns="False" Name="dgCommentHotKeyAssignment" RowBackground="White" Height="Auto" >
<DataGrid.Columns>
<DataGridTextColumn
Header="#" Width="Auto"
Binding="{Binding Path=CommentNumber}" IsReadOnly="True" CanUserResize="False" CanUserReorder="False">
</DataGridTextColumn>
<DataGridTextColumn
Header="Category" Width="Auto"
Binding="{Binding Path=CategoryDisplay}" IsReadOnly="True" CanUserReorder="False">
</DataGridTextColumn>
<DataGridTextColumn
Header="Comment Text" Width="150"
Binding="{Binding Path=CommentText}" CanUserReorder="False">
</DataGridTextColumn>
<DataGridComboBoxColumn Header="Shift Key">
<DataGridComboBoxColumn.ElementStyle>
<Style TargetType="ComboBox">
<Setter Property="Background" Value="{Binding Background}"/>
<Setter Property="IsEditable" Value="False"/>
<Setter Property="ItemsSource" Value="{Binding Source={StaticResource ShiftKey}}"/>
<Setter Property="Text" Value="{Binding Value}"/>
</Style>
</DataGridComboBoxColumn.ElementStyle>
<DataGridComboBoxColumn.EditingElementStyle>
<Style TargetType="ComboBox">
<Setter Property="Background" Value="{Binding Background}"/>
<Setter Property="IsEditable" Value="False"/>
<Setter Property="ItemsSource" Value="{Binding Source={StaticResource ShiftKey}}"/>
<Setter Property="Text" Value="{Binding Value}"/>
</Style>
</DataGridComboBoxColumn.EditingElementStyle>
</DataGridComboBoxColumn>
</DataGrid.Columns>
</DataGrid>






Responses

Posted by: Vuyiswamb on: 3/1/2011 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
I have not written a WPF app, as i am working on Silverlight i think the approach should be the same. Look at how i did it, but i used Telerk Datagrid
use the SelectionChanged event of the Datagrid as depicted below

   private void radGridView1_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangeEventArgs e)

{

BLL.LoginModel model = (BLL.LoginModel)this.radGridView1.SelectedItem;

objLoginDetails.txtFirstname.Text = model.sFirstName;
objLoginDetails.txtlastname.Text = model.sLastName;
objLoginDetails.txtUserID.Text = model.iUser_ID;
objLoginDetails.txtpassowrd.Text = model.sPassword;
objLoginDetails.txtactive.Text = model.sActive_YN;

}


i hope my code does not confuse you

Thank you for posting at Dotnetfunda
[Administrator]

Peermohamedmydeen, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response