假设有A窗体、B窗体(也可以理解为父窗体、子窗体)

A窗体代码文件中有DataGrid,其中有一个单元格的数据mySelectedRow.Row[3]作为要传递的ComboxBox 的value赋值给一个静态变量UserClass.UserGroupID

UserClass.UserGroupID =mySelectedRow.Row[3];

B窗体private void comboBoxUserGroup_Loaded(object sender, RoutedEventArgs e) 中绑定数据猿猴SelectedValuePath后增加下面这句:this.comboBoxUserGroup.SelectedValue = UserClass.UserGroupID;。完整的comboBoxUserGroup_Loaded代码如下:

private void comboBoxUserGroup_Loaded(object sender, RoutedEventArgs e)
{
comboBoxUserGroup.DataContext
= DalUserGroup.GetUserGroupItem();
DataSet ds
= DalUserGroup.GetUserGroupItem();
this.comboBoxUserGroup.ItemsSource = ds.Tables[0].DefaultView;
this.comboBoxUserGroup.DisplayMemberPath = "UserGroupName";
this.comboBoxUserGroup.SelectedValuePath = "UserGroupID";
this.comboBoxUserGroup.SelectedValue = UserClass.UserGroupID;
}

posted on 2011-04-27 00:34  dinid  阅读(1171)  评论(0编辑  收藏  举报