简体   繁体   English

组合框C#wpf中的值

[英]value in combobox C# wpf

i have combobox in datagrid (sourse in mysql (web)) how i can get value in select? 我在datagrid中有组合框(在mysql(web)中是源)我如何在select中获得价值?

<ComboBox SelectionChanged="status_SelectionChanged".........

c# C#

private void status_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    this here 
}

how??? 怎么样???

and how to get the value in another column, but in this line? 以及如何在另一列中获取值,但是在这一行中?

column_one   column_two

   value1      value2

Is change to column two , how getting column one? 更改为第二column two ,如何获得第一列?

update: my items 更新:我的物品

<ComboBox.Items>
    <ComboBoxItem>New</ComboBoxItem>
    <ComboBoxItem>Cancel</ComboBoxItem>
</ComboBox.Items>

You can access your combo box by name. 您可以按名称访问您的组合框。

<ComboBox SelectionChanged="status_SelectionChanged" Name="myComboBox" ... />
private void status_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    string value = myComboBox.SelectedItem.ToString();
}

How about this solution? 这个解决方案怎么样?

<ComboBox Name="myComboBox"  SelectionChanged="status_SelectionChanged" ... />

private void status_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var value = (sender as ComboBox).SelectedItem;
}

If you need to get value in other column but in same row, you can make new event for cells of your DataGrid and take needed value something like that 如果您需要在其他列但在同一行中获取值,则可以为DataGrid的单元格创建新事件并获取所需的值,例如

DataGrid.Item[var1,var2]

Where var1 is a row number and var2 column number. 其中var1是行号,var2是列号。

When I have to use Datagrid with complex cells, i save row and column number of each element (ComboBox in your case) in .Tag property, and eject it for determine cell number. 当我必须对复杂的单元格使用Datagrid时,我将每个元素的行和列号(在您的情况下为ComboBox)保存在.Tag属性中,然后将其弹出以确定单元格号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM