none
DataGrid Columns的bug RRS feed

  • 问题

  •  

    声明DataGrid设置 AutoGenerateColumns= "True"

    Code Snippet

           
                Height="120" Width="450" Margin="0,5,0,10"
                AutoGenerateColumns="True"
                RowBackground="LightSteelBlue"
                AlternatingRowBackground="Azure" />   

     

     

    程序执行时添加列

    Code Snippet

            public TDataGrid()
            {
                InitializeComponent();
                dataGrid1.ItemsSource = Customer.GetSampleCustomerList();
                dataGrid1.Columns.RemoveAt(2);

            }

     

     

    泛型类

     

    Code Snippet

        public class Customer
        {
            public String FirstName { get; set; }
            public String LastName { get; set; }
            public String Address { get; set; }
            public Boolean IsNew { get; set; }

            // A null value for IsSubscribed can indicate
            // "no preference" or "no response".
            public Boolean? IsSubscribed { get; set; }

            public Customer(String firstName, String lastName,
                String address, Boolean isNew, Boolean? isSubscribed)
            {
                this.FirstName = firstName;
                this.LastName = lastName;
                this.Address = address;
                this.IsNew = isNew;
                this.IsSubscribed = isSubscribed;
            }

            public static List GetSampleCustomerList()
            {
                return new List(new Customer[4] {
                    new Customer("A.", "Zero",
                        "12 North Third Street, Apartment 45",
                        false, true),
                    new Customer("B.", "One",
                        "34 West Fifth Street, Apartment 67",
                        false, false),
                    new Customer("C.", "Two",
                        "56 East Seventh Street, Apartment 89",
                        true, null),
                    new Customer("D.", "Three",
                        "78 South Ninth Street, Apartment 10",
                        true, true)
                });
            }
        }

     

     

    问题,自动添加列的时候Columns的Count一直都是0,RemoveAt(index)报错,发现只有在xaml声明时候定义了Column才能显示数量,自动添加列之后不能显示数量跟移除列,不知道大家遇到没有
    2008年8月10日 9:54
    版主

全部回复

  • 八爪,你自己解决吧!呵呵!


    努力!完成了js解析器,还差一个svg插件,一个绘图程序,做好自己,呵呵~!
    2011年7月11日 5:51
    版主