DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();
              newColumn.HeaderText = "选择";
              dataGridView.Columns.Insert(0, newColumn);
              dataGridView.MultiSelect = true;
              newColumn.InheritedStyle.Alignment = DataGridViewContentAlignment.TopCenter;
              newColumn.Width = 35;我用上面的方法给DataGridView添加了一列CheckBox,也设置了MultiSelect=True,为什么还是不能多选呢?望大虾们指点一下.谢谢.

解决方案 »

  1.   

    右键单击-DataGridView--编辑列--添加新列--ColumnType选择DataGridViewCheckBoxColumn
    就可以了
      

  2.   

    我试验了你的代码,可以支持多选啊。
    选了个checkbox,循环判断下checkbox的值为true,不就得到多条记录了吗
      

  3.   

    谢谢楼上兄弟的回答.那样不行的.因为我的DataGrideView是动态绑定xml文件的.所以只能手动添加CheckBoxColumn,可是加上后就是不能多选.我就实在想不通了
      

  4.   

    我以前用VS2005时也出现过这种情况。
    我的做法是:不要前面的勾,直接按ctrl进行多选,然后把selected的项全部输出就得到了所要的结果
      

  5.   

    以前好像碰到过类似问题
    我上次是xml文档的问题
    你用什么表示来表示的true false
      

  6.   

    楼主能把动态产生DataGrideView动态绑定xml文件的.相关代码贴上来分析一下啊
      

  7.   

    <?xml version="1.0"?>
    <GridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" PageSizes="20" VirtualMode="false" Width="0">
      <Columns DataPropertyName="LogContent" DataPropertyType="System.String" DefaultDraw="false" FormatString="" HeaderText="日志内容" IsComboBox="false" IsFill="false" IsKey="false" Ordinal="4" ReadOnly="true" Visible="true" Width="0" />
      <Columns DataPropertyName="Operator" DataPropertyType="System.Guid" DefaultDraw="false" FormatString="" HeaderText="操作员" IsComboBox="true" IsFill="false" IsKey="false" Ordinal="1" ReadOnly="true" Visible="true" Width="0" ValueMember="ID" DisplayMember="NameCn" />
      <Columns DataPropertyName="OperateTime" DataPropertyType="System.DateTime" DefaultDraw="false" FormatString="yyyy-MM-dd" HeaderText="操作时间" IsComboBox="false" IsFill="false" IsKey="false" Ordinal="5" ReadOnly="true" Visible="true" Width="0" />
      <Columns DataPropertyName="LogTypeID" DataPropertyType="JYWL.Sys.Share.SysLogType" DefaultDraw="false" FormatString="" HeaderText="操作类型" IsComboBox="false" IsFill="false" IsKey="false" Ordinal="2" ReadOnly="true" Visible="true" Width="0" />
      <Columns DataPropertyName="KeyWords" DataPropertyType="System.String" DefaultDraw="false" FormatString="" HeaderText="关键字" IsComboBox="false" IsFill="false" IsKey="false" Ordinal="3" ReadOnly="true" Visible="true" Width="0" />
      <Columns DataPropertyName="LogNO" DataPropertyType="System.Guid" DefaultDraw="false" FormatString="" HeaderText="序号" IsComboBox="false" IsFill="false" IsKey="true" Ordinal="0" ReadOnly="false" Visible="false" Width="0" />
    </GridConfig>
    这是绑定的xml文档.是不是这里面的问题?大哥些帮帮忙
      

  8.   

    晕.都没人会啊?用xml绑定你们都不做多选么?还是都没用xml绑定?
    谷歌和百度都找完了.没有答案啊.急死了
      

  9.   

     var grid=document.getElementById("<%=grid.ClientID%>");
       if(grid==null)
           return false;   
       
       var gi=grid.getElementsByTagName("input")
       for(var i=0;i<gi.length;i++)
       {
           if(gi[i].checked){
            flag=true;
           }
       }
      

  10.   

    我上次把表示true false改成了1,0表示就可以复选了
      

  11.   

    还有将复选框所在的column的truevalue和falsevalue属性加一下,写成true和false
    我上次是用的1,0
    你用true,false看看
      

  12.   


    这样还是不行 DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();
                newColumn.HeaderText = "选择";
                dataGridView.Columns.Insert(0, newColumn);//添加CheckBox
                newColumn.InheritedStyle.Alignment = DataGridViewContentAlignment.TopCenter;
                newColumn.Width = 35;
                newColumn.TrueValue = 1;
                newColumn.FalseValue = 0;
                dataGridView.MultiSelect = true;//设置可以选中多行
      

  13.   

    正解:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Info.aspx.cs" Inherits="AppModules_Asset_Info" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <script type="text/javascript">
        function CheckboxChoose(choosed)
    {
    var elementOnes=document.form1.elements;
    var boolAll=true;
    var controlAll; 

    for(var i=0;i<elementOnes.length;i++)
    {
    if(choosed.id.indexOf('CheckAll')!=-1)
    {
    elementOnes[i].checked=choosed.checked;
    controlAll=elementOnes[i];
    }
    else if(choosed.id.indexOf('DeleteThis')!=-1)
    {
    if(elementOnes[i].id.indexOf('CheckAll')!=-1)
    {
    controlAll=elementOnes[i];
    controlAll.checked=true;
    }
    if(elementOnes[i].checked==false)
    {
    boolAll=false;

    }
    }
    controlAll.checked=boolAll;
    }

    </script>
    <head runat="server">
        <title>无标题页</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <table>
                <tr>
                    <td style="width: 90px">
                        申请编号:</td>
                    <td style="width: 110px">
                        <asp:TextBox ID="txtId" runat="server"></asp:TextBox></td>
                    <td style="width: 70px">
                        申请人:</td>
                    <td style="width: 70px">
                        <asp:TextBox ID="txtName" runat="server"></asp:TextBox></td>
                    <td style="width: 70px">
                        <asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="查询" /></td>
                    <td style="width: 55px">
                        <asp:Button ID="btnAdd" runat="server" OnClick="btnAdd_Click" Text="添加" /></td>
                    <td style="width: 55px">
                        <asp:Button ID="btnUpdate" runat="server" Text="修改" OnClick="btnUpdate_Click" /></td>
                    <td colspan="4" style="width: 51px">
                        &nbsp;<asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" Text="删除"/></td>
                </tr>
            </table>
            <asp:GridView ID="gridBackNoteList" runat="server" AutoGenerateColumns="False" DataKeyNames="ASSETID"
                Width="701px">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:CheckBox ID="CheckAll" runat="server" onclick="return CheckboxChoose(this); " />
                        </HeaderTemplate>
                        <ItemStyle HorizontalAlign="Center" />
                        <ItemTemplate>
                            <input id="DeleteThis" name="DeleteThis" type="checkbox" value='<%# Eval("ASSETID")%>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:HyperLinkField DataNavigateUrlFields="ASSETID" DataNavigateUrlFormatString="Default2.aspx?id={0}"
                        DataTextField="ASSETID" HeaderText="申请人编号:">
                        <ItemStyle HorizontalAlign="Center" />
                    </asp:HyperLinkField>
                    <asp:BoundField DataField="ASSETNAME" FooterText="ASSETNAME" HeaderText="申请人:">
                        <ItemStyle HorizontalAlign="Center" />
                    </asp:BoundField>
                </Columns>
                <EmptyDataTemplate>
                    <thead>
                        <th>
                            申请人编号</th>
                        <th>
                            申请人</th>
                    </thead>
                    <tr class="data">
                        <td align="center" colspan="8">
                            暂无数据</td>
                    </tr>
                </EmptyDataTemplate>
            </asp:GridView>
        
        </div>
        </form>
    </body>
    </html>
      

  14.   

    TO:defeng520 
    兄弟,如果是B/S模式的就没这么麻烦了,一段js的代码就搞定了.关键现在是C/S模式下的
    而且绑定的是xml.不过还是谢谢你
    谁能解决.另外开贴送100分
      

  15.   

    truevalue和falsevalue的值要和你xml文档里属性的值一样
    你用的是true,false,
    我以前用的是1,0
      

  16.   

    我写了个demoxml 文档不变,用你的DataGridView设置DataGridViewCheckBoxColumn newColumn = new DataGridViewCheckBoxColumn();
                newColumn.HeaderText = "选择";            
                newColumn.InheritedStyle.Alignment = DataGridViewContentAlignment.TopCenter;
                newColumn.Width = 35;
                newColumn.TrueValue = "true";
                newColumn.FalseValue = "false";
                newColumn.DataPropertyName = "IsKey";
                this.dataGridView1.Columns.Insert(0, newColumn);               DataSet ds = new DataSet();
                ds.ReadXml(@"D:\Windows Project File\checkBoxDemo\checkBoxDemo\TestXMLFile.xml");
                this.dataGridView1.DataSource = ds.Tables["Columns"];运行结果ok
      

  17.   

    还有
    试试把你的DataGridView删掉,重新放一个,(怀疑你是不是修改了哪个属性,导致冲突)
      

  18.   

    天哪,那么难,我就想选中一行时,checkbox也能同时选中,默认一行也不选,没找到解决方法
      

  19.   

    wo 知道哪出来问题this.VirtualMode = false;这样就好了 md折腾我半个多小时
      

  20.   

    能不能让一个选中之后其他的Checkbox全部选中?