简体   繁体   English

WPF C#以另一种形式发送值并在组合框中绑定数据

[英]WPF C# Send Value in Another Form And Bind Data in Combobox

Hello i have one questions,i'm sending data with parameters from Form1 to Form2: 您好,我有一个问题,我正在将参数从Form1发送到Form2的数据:

DataRowView rowview = datagrid_system.SelectedItem as DataRowView;
        int id = Convert.ToInt32(rowview.Row[0]);
       Form2 be = new Form2(id);

And in Form2 Load I'm calling 1 function to binding from database all id in ComboBox1, but this is my problem for example in Form1 have ids(1,2,3,4,5) the user is selected id=3 and this id=3 is sending in Form2 I want to do this id=3 displaying in first combobox and other data displaying after this. 在Form2 Load中,我正在调用1个函数来从数据库中绑定ComboBox1中的所有id,但这是我的问题,例如在Form1中,具有ids(1,2,3,4,5)的用户被选择为id = 3,并且id = 3正在Form2中发送,我想在第一个组合框中显示此id = 3,此后显示其他数据。 Example: 例:

3->First data in combobox, other data is binding by function Form2 Load 3->组合框中的第一个数据,其他数据通过功能Form2加载进行绑定

1,2,4,5 1,2,4,5

In Form2 Load Binding Function: 在Form2负载绑定函数中:

 public void BindComboBox(ComboBox cmb_system)
    {
        MySqlConnection conn = new MySqlConnection(Connection.DB);
        MySqlDataAdapter da = new MySqlDataAdapter("Select id FROM db_systems", conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "db_systems");
        cmb_system.ItemsSource = ds.Tables[0].DefaultView;
        cmb_system.DisplayMemberPath = ds.Tables[0].Columns["id"].ToString();
    }

您必须更改表中的行顺序或添加列以对表进行排序,或者可能将其转换为另一个数据结构(例如列表)。

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

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