Hi

I have a lookup edit on the form, In the form load event i am setting the datasoure to the lookupedit and I want the first value in the datasoure to be selected in the lookupedit; for acheiving this explictly i am setting the editvalue to the lookup edit control.

Which triggers the Editvalue_Changed event, in this i want to get the another column value from the lookupedit.. for doing this i using GetColumnValue method which returns null..!!! what might be the reason..

Code Snippets:
Form Load event:

DataTable dt_DataTable = GetDataTable();
lookupedit.Properties.DataSource = dt_DataTable.DefaultView;
lookupedit.Editvalue = dt_Datatable.Rows[0]["ColumnName"]; //Which triggers the editvalue_changed event

Edit Value Changed Event:

string someval = lookupedit.GetColumnValue("SomeOtherColumn").ToString(); //returns null what might be reason???

to get the value what i have to do.. please suggest..???

Thanks and Regards,
Thameem.

 

Processed (Answered) by DevExpress Team

 

 

Hi Abdur,

Sorry for the delay in responding.
The GetColumnValue method won't work within the form load event, because the lookup control is not yet initialized. This will only work after the control is displayed. The easiest way to accomplish your task is to get a value directly from the data source by accessing it via the row key.
This can be done using the GetDataSourceRowByKeyValue method. Please look at the following code:
 

[C#]

//...
        lookUpEdit1.EditValueChanged += new EventHandler(lookUpEdit1_EditValueChanged);
            lookUpEdit1.EditValue = "ALFKI";
        }
        void lookUpEdit1_EditValueChanged(object sender, EventArgs e)
        {
            object row = lookUpEdit1.Properties.GetDataSourceRowByKeyValue(lookUpEdit1.EditValue);
            if (row != null)
            {
                string columnValue = ((DataRowView)row)["CompanyName"].ToString();
                MessageBox.Show(columnValue);
            }
        }
In addition, I suggest you review the How to obtain a value for a specific column within the LookupEdit which corresponds to the currently selected row article for more information about accessing values from the lookup editor.

 

Thanks
Dennis