vs2003 ,winform 下一个column绑定一个checkbox是很容易的,直接用DataGridBoolColumn设置就可以啦。
但是一个column如何绑定多个checkbox呢,我查了很多资料,都没找到解决方案,自己乱写了些代码,还是不行,有这方面经验的,请赐教!
我要实现的效果是这样的
---------------------------------------------------------------------------
|   第一列标题 |      第二列标题                                          |
|     value1   |  第一个checkbox, 第二个checkbox 共显示5个checkbox |
|     value2   |  第一个checkbox, 第二个checkbox 共显示5个checkbox |
|     value3   |  第一个checkbox, 第二个checkbox 共显示5个checkbox |
|     value4   |  第一个checkbox, 第二个checkbox 共显示5个checkbox |
|     value5   |  第一个checkbox, 第二个checkbox 共显示5个checkbox |
|     value6   |  第一个checkbox, 第二个checkbox 共显示5个checkbox |
|     value7   |  第一个checkbox, 第二个checkbox 共显示5个checkbox |
--------------------------------------------------------------------------明白我的意思了吧。这种如何实现呢?有没有人做过???????????写的部分代码在http://community.csdn.net/Expert/topic/4770/4770181.xml?temp=.5465357里

解决方案 »

  1.   

    http://www.syncfusion.com/faq/winforms/Files/datagridcheckbox.zip
    给你一个例子
    // code assumes you have a DataSet named myDataSet, a table named "EastCoastSales" and a DataGrid myDataGrid 
     
    //STEP 1: Create a DataTable style object and set properties if required. 
     
         DataGridTableStyle ts1 = new DataGridTableStyle(); 
      
         //specify the table from dataset (required step) 
     
         ts1.MappingName = "EastCoastSales"; 
     
          
     
         // Set other properties (optional step) 
     
         ts1.AlternatingBackColor = Color.LightBlue; 
      
    //STEP 2: Create a string column and add it to the tablestyle 
     
         DataGridColumnStyle TextCol = new DataGridTextBoxColumn(); 
     
         TextCol.MappingName = "custName"; //from dataset table 
     
         TextCol.HeaderText = "Customer Name"; 
     
         TextCol.Width = 250; 
     
         ts1.GridColumnStyles.Add(TextCol); 
      
    //STEP 3: Create an int column style and add it to the tablestyle 
     
         //this requires setting the format for the column through its property descriptor 
     
         PropertyDescriptorCollection pdc = this.BindingContext 
     
               [myDataSet, "EastCoastSales"].GetItemProperties(); 
      
         //now created a formated column using the pdc 
     
         DataGridDigitsTextBoxColumn csIDInt = 
     
               new DataGridDigitsTextBoxColumn(pdc["CustID"], "i", true); 
     
         csIDInt.MappingName = "CustID"; 
     
         csIDInt.HeaderText = "CustID"; 
     
         csIDInt.Width = 100; 
     
         ts1.GridColumnStyles.Add(csIDInt); 
      
    //STEP 4: Add the checkbox 
     
         DataGridColumnStyle boolCol = new DataGridBoolColumn(); 
     
         boolCol.MappingName = "Current"; 
     
         boolCol.HeaderText = "Info Current"; 
      
    //uncomment this line to get a two-state checkbox 
     
         //((DataGridBoolColumn)boolCol).AllowNull = false; 
      
         boolCol.Width = 150; 
     
         ts1.GridColumnStyles.Add(boolCol); 
      
    //STEP 5: Add the tablestyle to your datagrid's tablestlye collection 
     
         myDataGrid.TableStyles.Add(ts1);
     
      

  2.   

    把该列改为模板列,代码如下:<asp:TemplateField HeaderText="标题">
    <ItemStyle Width="60px" />
    <ItemTemplate>
       <asp:CheckBox ID="chk1" runat="server"></asp:CheckBox>
       <asp:CheckBox ID="chk2" runat="server"></asp:CheckBox>
       <asp:CheckBox ID="chk3" runat="server"></asp:CheckBox>
       ...
    </ItemTemplate>
    </asp:TemplateField>搞定,在要使用的时候用 (CheckBox)Grid.Rows[行号].FindControl("chk1") 即可找到对象使用了
      

  3.   

    上面的代码是写在: *.aspx 文件中的
      

  4.   

    To copico(一路向北) :
    我要实现一个单元格里,能包括5个checkbox,你的例子里只有一个checkbox。To dafeifei(大飞飞):
    我现在要在winform里实现,不是web form
      

  5.   

    To duguguiyu1984(把失败扼杀在摇篮中) :
      没错,是要继承的。我自己写了一个继承类http://community.csdn.net/Expert/topic/4770/4770181.xml?temp=.5465357
    只是只有在编辑状态下才显示出来。
      

  6.   

    把第二列放五个格子,每个格子里面一个checkbox,然后把这五列的标题合并单元格,变成一个,嘿嘿!
      

  7.   

    To zhoujijunnt(---) :
      你的方法如何实现呢?