我在C#中编写了一个程序,用于在数据库中搜索特定工具,并在DataGrid中显示该工具的规范。我被要求将DataGrid中的一个字段更改为ComboBox。我想我差不多了,但我似乎无法弄清楚如何把它放在我想要的栏目中。任何帮助将不胜感激。
WPF代码`
<DataGrid.Columns>
<DataGridComboBoxColumn Header="ComboBox" x:Name="comboboxColumn1"
SelectedValueBinding="{Binding ComboBox}" />
</DataGrid.Columns>
</DataGrid>
`
C#代码`
public partial class Termination : Window
{
DataTable Lds;
SqlDataAdapter adapter;
SqlConnection connection;
public List<string> GVComboBox { get; set; }
public Termination()
{
InitializeComponent();
GVComboBox = new List<string>() { "CRV Owned", "Customer Owned", "CRV Leased", "Customer Leased", "" };
comboboxColumn1.ItemsSource = GVComboBox;
}
private void ApplicatorB_Click(object sender, RoutedEventArgs e)
{
Common.sqlApplicator = "Select Terminal,Applicator,applicator_Type as 'Applicator Type',Hand_tool as 'Hand Tool', Hand_Tool_Type as 'Hand Tool Type',Wire_Gauge as 'Wire Gauge',Crimp_Height as 'Core Crimp Height',Conductor_Crimp_Width as 'Core Crimp Width',Insulator_Crimp_Height as 'Insulation Crimp Height',Insulator_Crimp_Width as 'Insulation Crimp Width',Tooling,Notes,Strip_Length as 'Strip Length',Applicator_Status as 'Applicator Status' ,ID from Tooling_Specs where Applicator like '" + ApplicatorTB.Text + "%' order by Applicator";
try
{
connection.Open();
adapter = new SqlDataAdapter(Common.sqlApplicator, connection);
Lds = new DataTable("Applicator");
adapter.Fill(Lds);
OutputDG.ItemsSource = Lds.DefaultView;
}
catch (Exception E)
{
MessageBox.Show(E.ToString());
}
finally
{
connection.Close();
};
Common.Applicator = ApplicatorTB.Text;
Common.Terminal = TerminalTB.Text;
Common.Tool = ToolTB.Text;
if (Common.admin == false)
{
ApplicatorTB.Clear();
}
}`