0
votes

I have a class called classA which the constructor used to accept a DataGridView argument.

Like so:

public class classA {
    readonly DataGridView thisClassData = default(DataGridView);
    public classA(DataGridView someData){
        Init();
        thisClassData = someData;
    }
}

I am making a call elsewhere like this:

classA classA_obj = classA(otherDataGridView.SelectedRows[0]);

I have now converted everything to use DevExpress, so in ClassA, I have changed DataGridView to GridView, however, I do not know how to pass in the selected rows as GridView. Can someone show an example of how this can be achieved?

2
otherDataGridView.SelectedRows[0] return the value of type DataGridViewRow. It's unclear how you are using this: classA classA_obj = new classA(otherDataGridView.SelectedRows[0]); because it does not compiles. What the type of otherDataGridView variable? - nempoBu4

2 Answers

0
votes

You cannot convert a DataGridView to a GridView.
What you can do, is get the data (or part of the data) of the DataGridView and set the DataSource property of the gridView. Something like this

List<classA > list = new List<classA >();
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
        list.Add((classA )dataGridView1.SelectedRows[i].DataBoundItem);

gridview.DataSource = list;
0
votes

It is impossible to convert a DataGridView to a DevExpress GridView. You should do everything from scratch. Also, (DevExpress) GridView.GetSelectedRows() method returns the row handles of selected rows.