【问题标题】:Telerik WinForms RadGridView create and fill in runtimeTelerik WinForms RadGridView 创建并填写运行时
【发布时间】:2014-02-26 13:30:22
【问题描述】:

我的问题与此非常相似

Fill RadGridView dynamically

但我不想创建数据表

这是网格视图

 GridView = new RadGridView
            {
                    AutoSizeRows = true,
                    BeginEditMode = RadGridViewBeginEditMode.BeginEditProgrammatically,
                    Location = new Point(0, 130),
                    Name = "GridView",
                    ShowRowErrors = false,
                    Size = new Size(390, 100),
                    TabIndex = 0,
                    Visible = false
            };

此方法在运行时创建列

 private List<GridViewTextBoxColumn> InitializeColumns()
    {
        var result = new List<GridViewTextBoxColumn>();

        {
            var columnId = new GridViewTextBoxColumn
                {
                    Name = "RecordID",
                    HeaderText = "ID",
                    FieldName = "RecordID",
                    MaxLength = 50,
                    Width = 50,
                    DataType = typeof(int)
                };
            result.Add(columnId);
        }

        {
            var columnInformation = new GridViewTextBoxColumn
                {
                    Name = "RecordInformation",
                        HeaderText = "Information",
                        FieldName = "RecordInformation",
                        MaxLength = 50,
                        Width = 250,
                        DataType = typeof(string)
                };
            result.Add(columnInformation);
        }

        {
            var columnRowType = new GridViewTextBoxColumn
            {
                Name = "RecordType",
                HeaderText = "Type",
                FieldName = "RecordType",
                MaxLength = 50,
                Width = 250,
                DataType = typeof(string)
            };
            result.Add(columnRowType);
        }

        return result;
    }

这个类用于网格行

internal class OrderTripChangedAlertItem
{
    public int RecordID { get; set; }
    public string RecordInformation { get; set; }
    public string RecordType { get; set; }

    public OrderTripChangedAlertItem(int recordID, string recordInformation, string recordType)
    {
        RecordID = recordID;
        RecordInformation = recordInformation;
        RecordType = recordType;
    }
}

所以我将列表绑定到网格视图。列显示正常,但未显示数据。必须有一个记录。我错过了什么?

【问题讨论】:

    标签: c# winforms gridview grid telerik


    【解决方案1】:

    这是我放在表单上的全部代码,它工作得很好:

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
    
            RadGridView GridView = new RadGridView
            {
                AutoSizeRows = true,
                BeginEditMode = RadGridViewBeginEditMode.BeginEditProgrammatically,
                Location = new Point(0, 130),
                Name = "GridView",
                ShowRowErrors = false,
                Size = new Size(390, 100),
                TabIndex = 0,
                //Visible = false,
                Parent = this
            };
    
            GridView.Columns.AddRange(InitializeColumns().ToArray());
    
            List<OrderTripChangedAlertItem> list = new List<OrderTripChangedAlertItem>();
            OrderTripChangedAlertItem item = new OrderTripChangedAlertItem(0, "some info", "some type");
            list.Add(item);
            GridView.DataSource = list;
        }
    
        private List<GridViewTextBoxColumn> InitializeColumns()
        {
            var result = new List<GridViewTextBoxColumn>();
    
            {
                var columnId = new GridViewTextBoxColumn
                {
                    Name = "RecordID",
                    HeaderText = "ID",
                    FieldName = "RecordID",
                    MaxLength = 50,
                    Width = 50,
                    DataType = typeof(int)
                };
                result.Add(columnId);
            }
    
            {
                var columnInformation = new GridViewTextBoxColumn
                {
                    Name = "RecordInformation",
                    HeaderText = "Information",
                    FieldName = "RecordInformation",
                    MaxLength = 50,
                    Width = 250,
                    DataType = typeof(string)
                };
                result.Add(columnInformation);
            }
    
            {
                var columnRowType = new GridViewTextBoxColumn
                {
                    Name = "RecordType",
                    HeaderText = "Type",
                    FieldName = "RecordType",
                    MaxLength = 50,
                    Width = 250,
                    DataType = typeof(string)
                };
                result.Add(columnRowType);
            }
    
            return result;
        }
    
        internal class OrderTripChangedAlertItem
        {
            public int RecordID { get; set; }
            public string RecordInformation { get; set; }
            public string RecordType { get; set; }
    
            public OrderTripChangedAlertItem(int recordID, string recordInformation, string recordType)
            {
                RecordID = recordID;
                RecordInformation = recordInformation;
                RecordType = recordType;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-22
      • 2021-04-29
      • 1970-01-01
      • 2016-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多