首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

WinForm->DataGridView->CheckedListBox解决方案

2012-09-14 
WinForm--DataGridView--CheckedListBox刚碰WinForm的新手求助:环境VS2010,WinForm开发问题:想实现winfo

WinForm-->DataGridView-->CheckedListBox
刚碰WinForm的新手求助:

环境VS2010,WinForm开发

问题:
想实现winform中datagridview中绑定三列,前两列是父对象id和父对象名称,第三列绑定该父对象下的所有子对象,每个父对象单独成一行,用于绑定子对象的第三列想用checkedListBox来做,因为涉及到批量删除。这个东东的WebForm版本实现是:父对象查出来是一个数据集,然后在在RowDataBound事件中 获取父对象的Id通过方法查出其下面所有子对象再绑给子对象对应CheckBoxList控件

求助:
问题1:WinForm中没有找到类似于WebForm中的RowDataBound事件,我查资料之后考虑用RowPrePaint不知道错了没
问题2:DataGridView中添加列好像没有CheckListBox的列,我上网找了一个微软大牛写的CheckedListBoxColumn.cs现在,,,WinForm中好像也木有FindControl这个方法,,,WebForm中是在RowDataBound中用FindControl找到CheckListBox然后绑数据源就可以了,WinForm中应该怎么做啊,,,,,

[解决办法]
这个你为什么不用TreeView+DataGridView来实现呢?
点击Treeview,DataGridview来显示子对象,列表用DataGridViewCheckBoxColumn,勾选删除不还简单些么?
[解决办法]

C# code
//全选private void btnAllchoose_Click(object sender, EventArgs e)        {      for (int i = 0; i < dataGridView1.Rows.Count; i++)            {                dataGridView1.Rows[i].Cells[0].Value = true;            }}//反选private void btnRchose_Click(object sender, EventArgs e)        {            for (int i = 0; i < dataGridView1.Rows.Count; i++)            {                DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[0];                if ((Boolean)chk.EditedFormattedValue == true)                {                    dataGridView1.Rows[i].Cells[0].Value = false;                }                else                    dataGridView1.Rows[i].Cells[0].Value = true;            }        } 

热点排行