与datagrid的组合框数据绑定 [英] Combobox databinding with datagrid

查看:130
本文介绍了与datagrid的组合框数据绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!
我正在用wpf构建应用程序,将组合框绑定到数据网格时遇到了问题.我在表单上有一个组合框 cbTeacher 和一个数据网格 dgteacher .


首先我使用服务填充组合框:

Hi everyBody!
i''m building an application in wpf and I''m facing a problem when binding my combobox to my datagrid. I''ve a combobox cbTeacher on my form and a datagrid dgteacher.


Firstly I fill my combobox using a service:

exemple: cbTeacger.ItemsSource = new ClientServices.ClientService().Services.svc_load_Teacher();


因为老师的信息来自另一个表.
所以当我放下组合框时,我会看到老师的全部清单.

第二
该组合框已绑定到我的datagrid(dgteacher),因此在完成表单并将数据保存到数据库后,我可以直接从datagrid看到存储在数据库中的所有信息行.

问题是,在浏览数据网格的每一行时,我看不到绑定到组合框的信息.
显然,组合框保持不变,就像没有selecteditem或selectedindex一样.我不知道为什么?

有人可以帮忙吗?


because the teacher informations comes from an other Table.
so when i drop down my combobox I have the entire list of my teachers.

Secondly
The combobox is binded to my datagrid (dgteacher) so that after completing the form and saving data to database I can see all lines of informations stored in database directly from the datagrid.

The problem is , when navigating through each line of my datagrid I don''t see the informations bound to my combobox.
Clearly the combobox stay like there is no selecteditem or selectedindex. I don''t know why??

Someone can help ?

推荐答案

ComboBox具有以下特性:
-DisplayMember和
-ValueMember
两者都表示ComboBox中的数据,但首先用于显示值,其次用于与SelectedValue和SelectedItem对应的链接值.

开始在datagrid中浏览槽线之前,请尝试将ComboBox值存储在变量中.
ComboBox has the fallowing properties:
- DisplayMember and
- ValueMember
Both represents data in ComboBox, but first for displaying values, second for linked values which corresponds with SelectedValue and SelectedItem.

Before you start navigate trough lines in datagrid, try to store ComboBox value in variable.


这篇关于与datagrid的组合框数据绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆