Kliver Max
Kliver Max

Reputation: 5299

How to get GridLookUpEdit's EditValue?

I have a GridLookUpEdit and wath to get a edit value on FocusedRowChanged event:

    private void gridView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
    {
        var view = sender as GridView;
        if (view != null)
        {
            MessageBox.Show(view.GetRowCellValue(e.FocusedRowHandle, view.Columns[1]).ToString());
        }
    }

But here i get a error says that i out of column array. But i have a two columns, first column visible, second not visible.
Whats wrong here? And how can i get EditValue more correctly if possible?

Upvotes: 0

Views: 1995

Answers (1)

nempoBu4
nempoBu4

Reputation: 6621

It seems that your view has only one column and there are two columns in your underlying datasource. So, you can get a value from underlying datasource.
If your underlying datasource is DataTable then you can use ColumnView.GetDataRow method:

MessageBox.Show(view.GetDataRow(e.FocusedRowHandle)[1].ToString());

If your underlying datasource is List<SomeObject> then you can use ColumnView.GetDataSourceRowIndex method:

MessageBox.Show(YourList[view.GetDataSourceRowIndex()].YourColumn.ToString());

Or you can add second column by using ColumnView.Columns collection:

var column = view.Columns.AddField("YourField");
column.Visible = false;

Upvotes: 1

Related Questions