本文介绍了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;

推荐答案

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中的网格控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 21:37
查看更多