0

I am new on devexpress,so I have a simple question here.what is the equal of the this code on 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();
}
2
  • Please use the DevExpress help that comes with lots of examples or see the DevExpress Help center website...at least do some effort from your side first. Commented Jun 24, 2014 at 11:50
  • Thanks @NeillVerreynne for your comment.But i had googled it and found no exact answer that matches my Question. Commented Jun 25, 2014 at 4:06

1 Answer 1

1

The grid does not store data. It means, that you must add rows to its DataSource to force the control to display them. Here is the very simple code which does this:

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));
        }
    }
Sign up to request clarification or add additional context in comments.

2 Comments

Might need a gridView1.RefreshData() after the for loop as well. I've never quite figured out when it's needed and when it automatically triggers
Thanks @platon.I will use datasource to populate devexpress Grid view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.