c# - 当值来自 WCF 服务时,不会设置 ComboBox SelectedValue
问题描述
我遇到了一个奇怪的问题,即未设置组合框的 SelectedValue 并且始终保持其默认的第一个元素。我正在使用带有 .Net 4.6.1 的 Windows 窗体
组合框数据源来自 WCF 服务(返回列表),我想知道这是否可能是问题所在。这是我到目前为止所做的,我标记了不起作用的部分。
奇怪的是我可以看到该值设置正确(使用调试器)但组合框仍然没有改变。
private void ReporteTecnicoVerDetalle_Load(object sender, EventArgs e) {
try {
cmbTecnico.DataSource = util_service.ListarPersonas(5);
cmbTecnico.DisplayMember = "Nombre_persona";
cmbTecnico.ValueMember = "Id_persona";
} catch (Exception ex) {
MessageBox.Show("Error al poblar las personas: " + ex.Message);
}
try {
cmbProyecto.DataSource = util_service.ListarProyectos();
cmbProyecto.DisplayMember = "Nom_proyecto";
cmbProyecto.ValueMember = "Id_proyecto";
} catch (Exception ex) {
MessageBox.Show("Error al poblar los proyectos: " + ex.Message);
}
ReporteTecnicoBE rtecBE = tecSvc.MostrarReporte(idReporte);
// The options get populated properly above, but when I set the Selected value it does not work
cmbProyecto.SelectedValue = rtecBE.Id_proyecto; // "Id_proyecto" is an int
cmbTecnico.SelectedValue = rtecBE.Id_tecnico; // "Id_tecnico" as is this
// All other fields work fine
txtDetalle.Text = rtecBE.Detalles_reporte;
txtId.Text = rtecBE.Id_proyecto.ToString();
dtpFecha.Text = rtecBE.Fecha_reporte.ToString();
}
谢谢!
解决方案
推荐阅读
- python - 并行时间功能和非阻塞输入
- javascript - 我可以在单击图标时显示确认信息吗?
- r - 如何在 R 中生成这样的点图?
- javascript - 如何暂停承诺,直到我在 js、firebase 中获得用户操作?
- php - 如何在 PHP 中更改 Google 表格的缩放级别
- r - R降价主题不编织
- javascript - 如何淡化元素背景图像的边缘以与主背景图像融合?
- swift - 使用 GCD,DispatchGroup 如何在组离开之前(或之后)从后台队列在主队列上运行项目,而不会出现死锁?
- android - Jenkins - 移动 .android 文件夹位置
- flutter - 无法从 Firebase 中检索数据,并且它不显示来自 Firebase 的数据