如题,web的好做,winform里的到是不知道怎么下手了,请达人指教。

解决方案 »

  1.   

    Q: How can I put a checkbox in a column of my DataGrid?(.net winform)You create a custom DataTableStyle that contains column styles for each column you want to display. You add the column styles in the order you want them to appear. Here are the steps to add an string column, an int column and a bool check column to a DataGrid. You can also download a working project. 
     
    // 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.   

    wxqq2001(就让我用一生等待) 这个可以的。我改了这个实现了嵌套combox,checkbox差不多。
      

  3.   

    没有楼上的这么复杂,这个问题很好解决.只要将相关字段定义成BOOL类型,再绑到datagrid里,datagrid会自动将其转成checkbox.
      

  4.   

    当然如果要实现combox等复杂控件才有必要向一楼所说采用DataGridTableStyle方式,但是如果没这个需求为什么要这么麻烦,简洁为美!
      

  5.   

    this.checkboxCol.Columncheckbox.click += new System.EventHandler(checkboxCol_Columncheckbox_click);
    checkboxCol_Columncheckbox_click(object sender, System.EventArgs e)
    {}只要你找到这个checkbox即可,其实它只是嵌套了,还是checkbox,没有太大 的变化的。
      

  6.   

    那怎么作一次选中所有checkbox的功能?
    还有我发现现在选中一个checkbox要在单元格里点两下才行,第一下选中单元格第二下才选中checkbox,能改成一次就选中checkbox吗?