简体   繁体   中英

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:

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. Example:

3->First data in combobox, other data is binding by function Form2 Load

1,2,4,5

In Form2 Load Binding Function:

 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();
    }

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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