比如:我有一个DataGridViewe有一列是CheckBox的 有些行可以进行复选进行操作,有些不用,不用的我不想把CheckBox显示出来该怎么做?这里都使 高手,指导一下吧~
同理还有如何这列使Image的 如何使某行该图片不显示出来。

解决方案 »

  1.   

    this.GridView1.Rows[0].Cells[0].Visible = false;
       上面的代码是第一行 第一列不显示   
        或者第一行  某一列 this.GridView1.Rows[0].Cells["列名"].Visible = false;
      以此类推 
      

  2.   

    EmployeesGridView.Rows[0].Cells[3].Visible = !EmployeesGridView.Rows[0].Cells[3].Visible;
    就可以<body>
        <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <br />
            <br />
            <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
            <br />
            <br />
        </div>
        <div>
            <asp:GridView ID="EmployeesGridView" runat="server" 
                                    BackColor="LightGoldenrodYellow" BorderColor="Tan"
                                    BorderWidth="1px" CellPadding="2" ForeColor="Black" GridLines="None" 
                                    AutoGenerateColumns="False" Width="518px"
                                    >
                                    <FooterStyle BackColor="Tan" />
                                    <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
                                    <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" HorizontalAlign="Center" />
                                    <HeaderStyle BackColor="Tan" Font-Bold="True" />
                                    <AlternatingRowStyle BackColor="PaleGoldenrod" />
                                    <Columns>
                                        <asp:BoundField DataField="EmployeeID" HeaderText="Employee ID" />
                                        <asp:BoundField DataField="LastName" HeaderText="Last Name" />
                                        <asp:BoundField DataField="FirstName" HeaderText="First Name" />                                    
                                        <asp:ButtonField Text="Button" />
                                        <asp:TemplateField>
                                            <ItemTemplate>
                                                <asp:CheckBox ID="CheckBox1" runat="server" Text="CK" />
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                    <PagerSettings PageButtonCount="5" />
                                </asp:GridView>
        </div>
        </form>
    </body>using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using System.Collections.Generic;namespace WebApplication1
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            private List<Employee> EmployeeList;
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    EmployeeList = new List<Employee>();
                    EmployeeList.Add(new Employee(1, "Jump", "Dan"));
                    EmployeeList.Add(new Employee(2, "Kirwan", "Yvette"));
                    ViewState["EmployeeList"] = EmployeeList;
                }
                else
                    EmployeeList = (List<Employee>)ViewState["EmployeeList"];            EmployeesGridView.DataSource = EmployeeList;
                EmployeesGridView.DataBind();
            }        protected void Button1_Click(object sender, EventArgs e)
            {
                EmployeesGridView.Rows[0].Cells[3].Visible = !EmployeesGridView.Rows[0].Cells[3].Visible;
                EmployeesGridView.Rows[0].Cells[4].Visible = !EmployeesGridView.Rows[0].Cells[4].Visible;
            }    }
        [Serializable]
        public class Employee
        {
            private int _employeeID;
            private string _lastName;
            private string _firstName;        public int EmployeeID
            {
                get { return _employeeID; }
            }        public string LastName
            {
                get { return _lastName; }
            }        public string FirstName
            {
                get { return _firstName; }
            }        public Employee(int employeeID, string lastName, string firstName)
            {
                _employeeID = employeeID;
                _lastName = lastName;
                _firstName = firstName;
            }    }
    }
      

  3.   

    [Quote=引用 4 楼 yuanmanguo 的回复:]
    EmployeesGridView.Rows[0].Cells[3].Visible = !EmployeesGridView.Rows[0].Cells[3].Visible; 
    就可以 
    /Quote]
    我弄不明白为什么都使 搞.NET 开发,怎么连web控件gridview和winform控件DataGridViewe都不分?我说的是DataGridView
      

  4.   

    嗯,微软提供的这个控件的确不能单独对一个cell操作,只能设置整列获取某个cell值。第三方控件的话一般都可以支持,或者你重写那个DataGridView。
    如果楼主要求不高,可以设置cell的ReadOnly属性,那个是可以修改的。
      

  5.   

    CheckBox这列你不是绑定上去的吗?你可以在DataGridView控件cell事件中加判断,如果这列需要修改,哪么你绑定CheckBox,反之取消.这不就行了吗?
      

  6.   

    重写DataGridViewCell类的OnPaint方法。
    或者重写DataGridViewRow类的OnPaintCells方法。没有属性可以让你去控制单个CELL的可见性。因为datagridview的所有子对像都是要对齐的。
      

  7.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
               if (e.Row.Cells[1].Text == "0")  //判断是否显示的条件
                {
                    e.Row.Cells[9].Text = "";  //把第10列的单元格清空
                }
       }
    }
      

  8.   

    你可以动态设置某个单元格的类型啊。
    把不想要的类型设为文本类型比如说你要第一行,第一个单元格是 :
    this.dgv.rows[0].cell[0]=new DataGridViewTextBoxCell();
    this.dgv.rows[0].cell[0].value=null;
    比如说你要第一行,第二个单元格显示:
    this.dgv.rows[0].cell[0]=new DataGridViewCheckBoxCell();
      

  9.   

    人家的是winform 你用web的代码搞球 专业点行不