求教强制转换为RadioButton失败
我的代码中有这一句:
((RadioButton)this->Controls[j]->Controls[m]).Checked = true;
编译时提示错误如下:
1>e:\modifydata\modifydata\Form1.h(613) : error C2440: 'type cast' : cannot convert from
'System::Windows::Forms::Control ^' to 'System::Windows::Forms::RadioButton'
1> Conversion requires a constructor or user-defined-conversion operator, which can't be
used by const_cast or reinterpret_cast
1>e:\modifydata\modifydata\Form1.h(613) : error C2101: '&' on constant
1>e:\modifydata\modifydata\Form1.h(613) : error C2101: '&' on constant
1>e:\modifydata\modifydata\Form1.h(613) : error C2101: '&' on constant
1>e:\modifydata\modifydata\Form1.h(613) : error C2100: illegal indirection
我的程序效果如图:
一个窗体上有几个groupbox,每个groupbox中有几个RadioButton
请问为什么不能转换呢?在线等各位帮助
如果这句话有错,我应该怎么设置单选按钮选中呢
需要更全的代码吗
[解决办法]
groupbox存在非RadioButton元素,比如label或者间隔横线,或者越界导致,((RadioButton)this->Controls[j]->Controls[m]).Checked = true;之前最好先判断,是否是RadioButton
没见你的源代码,也不知到你用的什么界面库,根据经验判断的