WPF DataGridComboBoxColumn绑定问题 [英] WPF DataGridComboBoxColumn Binding Issue

查看:63
本文介绍了WPF DataGridComboBoxColumn绑定问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是第一次在WPF中构建应用程序。该应用程序旨在跟踪公司雇用的员工,跟踪雇用类型​​(例如......分配类别......全职,兼职,季节性,实习)。此外,它还将跟踪员工在公司任职期间分配给哪个部门
。有些员工在受雇期间会接触到几个不同的部门,以便更全面地完成他们的培训或工作量。

I am building an application in WPF for the first time. The application is intended to track employees who are hired by the company, track the hire type (e.g…assignment category…full time, part time, seasonal, intern). In addition, it will track which department to which an employee is assigned during their tenure with the company. Some employees are exposed to several different departments while employed in order to more fully round out their training or due to work loads.

此应用程序的后端内置在SQL Server中并包含三个表。他们是公司员工,公司部门和任务类别。每个显然都有自己的主键。

The backend for this application is built in SQL Server and contains three tables. They are company employees, company departments, and assignment categories. Each obviously has its own primary key.

我创建了一个数据网格,通过Linq到SQL类,显示公司employees表中的数据。 datagrid中的每个列都是DataGridTextColumn,但DataGridComboBoxColumn除外。 DataGridTextColumn的工作正常。但是,
我似乎无法使绑定正确。该列出现在数据网格中,是一个有效的组合框。问题是我无法找到如何使用最终用户将选择的值填充combox。这个组合框将允许最终用户选择
,该雇员已被雇用在哪个分配类别。

I have created a datagrid that, via Linq to SQL Classes, displays data from the company employees table. Each of the columns in the datagrid is a DataGridTextColumn except for one which is a DataGridComboBoxColumn. The DataGridTextColumn’s work fine. However, I cannot seem to get the binding correct. The column appears in the datagrid and is a working combobox. The issue is that I cannot find how to populate the combox with values from which the end user will select. This combobox will allow the end user to choose which under which assignment category an employee has been hired.

作为最终结果,该应用程序将由公司所有者用于跟踪他手头的员工数量,并显示每个月由于是季节性工人或实习生将离开的人。

As an end result, this application will be used by the company owner to keep track of the number of employees that he has on hand and show who will be leaving each month due to being a seasonal worker or an intern.

下面是代码和xaml。请注意,我已经花了几天时间研究这个主题,找不到任何可以工作的东西。我相信这是因为我只是在学习xaml和c#。

Below is the code behind and the xaml. Please note that I have spent several days now researching this topic and cannot find anything that I can make work. I am confident that this is because I am just learning xaml and c#.

有人能帮我理解我做错了吗?

Can someone help me understand what I am doing wrong, please?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;  
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace staff_scheduling_tool.views
{
  /// <summary>
  /// Interaction logic for employees_new_employee.xaml
  /// </summary>
  public partial class employees_new_employee : UserControl
{

assignment_typeDataContext dc = new assignment_typeDataContext(Properties.Settings.Default.db_employee_scheduling_applicationConnectionString);

  public employees_new_employee()
{
InitializeComponent();

  if (dc.DatabaseExists()) datagrid_search_results.ItemsSource = dc.companyemployees;

}
  private void Save_changes_Click(object sender, RoutedEventArgs e)
{
dc.SubmitChanges();
}
}
}





<DataGrid Name="datagrid_search_results" Margin="10,25" Width="1400" Height="350" AlternatingRowBackground="LightGreen" GridLinesVisibility="None" SelectionUnit="Cell" BorderBrush="Transparent" BorderThickness="0" Background="Transparent" AutoGenerateColumns="False">
      <DataGrid.Columns>
      <DataGridTextColumn Binding="{Binding employee_id}" Width="Auto" Header=" Employee ID" />
      <DataGridTextColumn Binding="{Binding last_name}" Width="Auto" Header=" Last Name" SortDirection="Ascending" />
      <DataGridTextColumn Binding="{Binding first_name}" Width="Auto" Header=" First Name"/>
      <DataGridTextColumn Binding="{Binding middle_name}" Width="Auto" Header=" Middle Name"/>
      <DataGridTextColumn Binding="{Binding company_email}" Width="Auto" Header=" Company Email"/>
      <DataGridComboBoxColumn Width="Auto" Header="Assignment Category" />
      <DataGridTextColumn Binding="{Binding department_assignment_begin_date, StringFormat=d}" Width="Auto" Header=" Begin Date"/>
      <DataGridTextColumn Binding="{Binding department_assignment_end_date, StringFormat=d}" Width="Auto" Header=" End Date"/>
      </DataGrid.Columns>
      </DataGrid>
      <Grid>
      <Grid.RowDefinitions>
      <RowDefinition Height="45"/>
      </Grid.RowDefinitions>
      <Button Name="save_changes" Content="Save Updates" Click="Save_changes_Click" Grid.Row="0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Width="250" FontFamily="Sitka Banner" FontSize="24" FontStyle="Italic" FontWeight="ExtraBold"/>

      </Grid>

推荐答案

您好,

根据您的描述,您的问题与Windows Presentation Foundation(WPF)有关。因此,为了更有效地处理这个问题,我将把这个帖子移到相应的论坛:
Windows Presentation Foundation(WPF)以获取专门信息。

According to your description, your issue is more related about Windows Presentation Foundation (WPF). So, to handle the issue more efficiently, I will move this thread to corresponding forum: Windows Presentation Foundation (WPF) for dedicated information.

感谢您的理解。

问候,

Kyle


这篇关于WPF DataGridComboBoxColumn绑定问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆