在DatagridviewComboBoxCell中显示值 [英] Display value in DatagridviewComboBoxCell
本文介绍了在DatagridviewComboBoxCell中显示值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有DatagridviewComboBoxColumn的网格。
我的代码在下面
I have a grid with DatagridviewComboBoxColumn.
My codes are below
DataTable dtoccupancy = bLRoomCheckIn.ReadOccupancy();
if (dtoccupancy.Rows.Count > 0)
{
for (int i = 0; i < dgvRoomRate.Rows.Count; i++)
{
(dgvRoomRate.Rows[i].Cells[2] as DataGridViewComboBoxCell).DataSource = dtoccupancy;
(dgvRoomRate.Rows[i].Cells[2] as DataGridViewComboBoxCell).ValueMember = "MasterId";
(dgvRoomRate.Rows[i].Cells[2] as DataGridViewComboBoxCell).DisplayMember = "Name";
}
}
但它没有显示单元格中的数据,
PLease帮助
But it didn't shows the data in the cell,
PLease Help
推荐答案
我运行了您的代码,您发布的代码段没有任何问题。
因此:
- dtoccupancy尚未填充(即dtoccupancy .Rows.Count == 0
)
或
- 未填充dgvRoomRate(即dgvRoomRate.Rows.Count == 0
)
问题可能在bLRoomCheckIn.ReadOccupancy()
你还没有分享。
但是,如果你说单元格显示为空,但你想要立即显示一些数据(在使用点击之前)下拉列表)然后您还必须将值
设置为有效值。例如。
I've run your code and there is nothing wrong with the code segment that you have posted.
Therefore either:
- dtoccupancy has not been populated (i.e.dtoccupancy.Rows.Count == 0
)
or
- dgvRoomRate is not populated (i.e.dgvRoomRate.Rows.Count == 0
)
The problem could be inbLRoomCheckIn.ReadOccupancy()
which you haven't shared.
If however, you are saying that the cell is displaying as empty, but you want some data to show immediately (before the use clicks the dropdown) then you also have to set theValue
to a valid value. E.g.
(dataGridView1.Rows[i].Cells[2] as DataGridViewComboBoxCell).Value = dtoccupancy.Rows[0][MasterId];
将值设置为第一个列表(假设数据表已填充)。
如果这不能解决您的问题,请使用有问题或评论吗?链接下面的回复和编辑您的问题,以发布 ReadOccupancy
方法的代码
will set the value to the first thing on the list (assuming the datatable is populated).
If this doesn't solve your problem then use the "Have a Question or Comment?" link below to respond and edit your question to post the code for the ReadOccupancy
method
对不起,我的数据专栏的名称是一个错误的一个所以它抛出错误
任何方式非常感谢
Sorry folks my dataproperty name for the column was a wrong one so it throws the error
any way thanks alot
这篇关于在DatagridviewComboBoxCell中显示值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文