WPF中的网格控件 [英] Grid Controls in WPF

查看:79
本文介绍了WPF中的网格控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

带下划线的短语给出了错误GridControl1是一个字段但是像一个类型一样使用



我该如何解决这个问题?







Underlined phrases gave that error "GridControl1 is a field but used like a type"

How can i solve this?



public DataView Data        
        {
            get
            {
                Excel.Application excelApp = new Excel.Application();
                Excel.Workbook workbook;
                Excel.Worksheet worksheet;
                Excel.Range range;
                workbook = excelApp.Workbooks.Open(Environment.CurrentDirectory + "\\Excel.xlsx");
                worksheet = (Excel.Worksheet)workbook.Sheets["Test Sheet"];//.get_Item(1);

                int column = 0;
                int row = 0;
                GridControl1 Gd = new GridControl1(); 

                range = worksheet.UsedRange;

                GridControl1 Gd = new GridControl1(); 
                
                Gd.Columns.Add("ID");
                Gd.Columns.Add("Name");
                Gd.Columns.Add("Position");
                Gd.Columns.Add("Web Site");
                
                for (row = 2; row <= range.Rows.Count; row++)
                {
                 DataRow dr = Gd.NewRow();
                 for (column = 1; column <= range.Columns.Count; column++)
                    {
                 dr[column - 1] = (range.Cells[row, column] as Excel.Range).Value2.ToString();
                    }
                    Gd.Rows.Add(dr);
                    Gd.AcceptChanges();
                }
                workbook.Close(true, System.Type.Missing, System.Type.Missing);
                excelApp.Quit();
                return Gd.DefaultView;

推荐答案

您的代码中有错误。我猜在页面上有一个带有ID''GridControl1'的GridControl控件,你用这个代码创建它的'ID'实例 - 这也是同一范围内的两次......

You have a mistake in your code. I guess there is a GridControl control on the page with ID ''GridControl1'' and you are creating the instance of its ''ID" with this code-And that too, two times in the same scope...
GridControl1 Gd = new GridControl1();

              range = worksheet.UsedRange;

              GridControl1 Gd = new GridControl1();





相反,您应该像这样创建Gridview控件的实例 -



Rather you should create a instance of Gridview control like this -

GridControl Gd = new GridControl();
              range = worksheet.UsedRange;


这篇关于WPF中的网格控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆