TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Erick Andrade
NA
1
2.8k
How get value of DataGridComboBoxColumn WPF?
Aug 6 2015 11:43 AM
Hi, well I don´t know how get value the combobox in my datagrid. I need that when I press the buttonSave, I can get the value of items selected in the combobox.
In XAML I have:
<DataGrid Name="DataGridFile" SelectionMode="Extended" SelectionUnit="Cell" ColumnWidth="*" HorizontalAlignment="Left" VerticalAlignment="Top" ItemsSource="{Binding Path=DataGRid, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False" CanUserAddRows="False" Margin="20,80,0,0" Height="304" Width="1140" RowHeaderWidth="0">
<DataGrid.Columns>
<DataGridTextColumn Header="Date" Binding="{Binding Path=Date}" IsReadOnly="True"/>
<DataGridComboBoxColumn Header="Asignar" x:Name="ComboBoxUser" DisplayMemberPath="Name" ItemsSource="{Binding UsuarioAssets}" SelectedItemBinding="{Binding Path=Name}" />
<DataGridTemplateColumn Header="Acción">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="Save" CommandParameter="{Binding Path=ID}" Click="ButtonSave_Click" ClickMode="Press" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
In the xaml.cs :
public class Users
{
public string Id { set; get; }
public string Name { set; get; }
}
List<Users> userlist = new List<Users>();
for (int j = 0; j < dtUser.Rows.Count; j++)
{
if (dtUser.Rows[j][3].ToString().Trim() != "admin")
{ userlist.Add(new UsuarioAssets { Id = j.ToString(), Name = dtUser.Rows[j][3].ToString() }); }
}
ComboBoxUser.ItemsSource = userlist;
//Note: With this I can see the users en my combobox
private void ButtonSave_Click(object sender, RoutedEventArgs e)
{
// I don´t know how get item selected
}
In internet I read that I get value with Datagrid.Rows but .Rows isn´t in System.Windows.Controls only in System.Windows.Forms
I hope you can help me!
Reply
Answers (
0
)
How to use PSD in WPF progressbar?
how to defind dynamic column of this table ( ListView ) ?