C#中给combobox赋值的问题..
- C# code
//单击客房在不可读区显示客房信息 private void dgvRoomInfoList_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { index = dgvRoomInfoList.SelectedCells[0].RowIndex; List<Room> rooms = dgvRoomInfoList.DataSource as List<Room>; Room room=rooms[index]; manager.SearchRoom(room); //赋值 txtNumber_2.Text = room.Number; txtGuestNumber_2.Text = room.GuestNumber.ToString(); txtBedNumber_2.Text = room.BedNumber.ToString(); cboState_2.Text=room.State;//此处 txtDescription_2.Text = room.Description; }
取到了State的值,但为什么给cboState_2赋值的时候,这上面的文本为空?
[解决办法]
能不能直接赋值和combobox的DropDownStyle属性有关
为simple时,可直接赋值。
为dropdownlist时,当赋值在下拉列表及Items.Collection中时,可直接赋值。否则赋值不成功。