【问题标题】:adding Rows on devexpress Grid using for loop in datatable在数据表中使用 for 循环在 devexpress Grid 上添加行
【发布时间】:2014-06-24 10:10:20
【问题描述】:

我是 devexpress 的新手,所以我在这里有一个简单的问题。devexpres gridview 上的这段代码等于什么。

for(int i=0;i<dtable.rows.count;i++)
{
  myGridview.Rows.Add();
  myGridview.Rows[i].Cells[0].value =dtable.Rows[i][0].tostring();
  myGridview.Rows[i].Cells[1].value = dtable.Rows[i][1].tostring();
}

【问题讨论】:

  • 请使用附带大量示例的 DevExpress 帮助或查看 DevExpress 帮助中心网站...至少先从您这边做一些努力。
  • 感谢@NeillVerreynne 的评论。但我用谷歌搜索并没有找到与我的问题匹配的确切答案。

标签: c# devexpress


【解决方案1】:

网格不存储数据。这意味着,您必须向其 DataSource 添加行以强制控件显示它们。这是执行此操作的非常简单的代码:

public class Record {
        public Record(int id) {
            this.Id = id;
            this.Data = string.Format("Record {0}", id);
        }
        public int Id { get; set; }
        public string Data { get; set; }
    }

    public partial class Form1: Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {

            BindingList<Record> dataSource = new BindingList<Record>();
            gridControl1.DataSource = dataSource;
            for(int i = 0; i < 10; i++)
                dataSource.Add(new Record(i));
        }
    }

【讨论】:

  • 在 for 循环之后可能还需要一个 gridView1.RefreshData() 。我从来没有完全弄清楚什么时候需要它以及什么时候它会自动触发
  • 感谢@platon。我将使用数据源填充 devexpress 网格视图。
猜你喜欢
  • 2013-11-11
  • 1970-01-01
  • 2019-11-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多