在PDA开发中往往会用到Resco开发的控件,其中smartgrig想必都用过,但是在其中加入checkbox列后会出现很多问题:点击后没有反应,设定值不起作用等,以下是自己的解决的过程,记录下来以备下次再走弯路,也让有相同困惑的人能有帮助。
首先在设定smartgrid中设定是
column1.CellEdit = Resco.Controls.SmartGrid.CellEditType.CheckBox;//设定colomn1列为checkbox列,显示复选框
column1.EditMode = Resco.Controls.SmartGrid.EditMode.OnEnter;//设定colomn1列的编辑方式,如果没有此句,事件不会响应
smartGrid1.CheckBoxEdit += new Resco.Controls.SmartGrid.CheckBoxEditHandler(sg_chageCheckBox);//设定编辑事件
有了上面的语句,checkbox列就设定好了,不过不知道为什么此列的值是“"0","1"”或“"false","true"”这是查找官网得知的,而不是0,1或false,true;
下面是事件内容:
void sg_chageCheckBox(object sender, Resco.Controls.SmartGrid.CheckBoxEditEventArgs e)
{
if (sg.SelectedCell.RowIndex > -1)
{
sg.Cells[sg.SelectedCell.RowIndex, 2].Text = (sg.Cells[sg.SelectedCell.RowIndex, 2].Text == "0" ? "1" : "0");
}
}
有了这样就OK。