[DevExpress Support Team: CLONED FROM A495: How to obtain the selected row from the LookUp editor]
Would you so kind to share the solution for us all?? im also looking for the How to Retrieve the Value Corresponding to the Currently Selected Display Value of the RepositoryItemGridLookUpEdit???
We have closed this ticket because another page addresses its subject:
RepositoryItemGridLookUpEdit - How to get a selected row's column valueGridLookUpEdit - How to Retrieve the Value Corresponding to the Currently Selected Display Value?
Answers approved by DevExpress Support
Hello,
This issue has been already discussed in the RepositoryItemGridLookUpEdit - How to get a selected row's column value thread. The main idea is to use the RepositoryItemGridLookUpEdit.GetRowByKeyValue method to obtain a row object from a GridLookUpEdit drop-down list. Please refer to the mentioned thread for more information.
Should you have additional questions, let us know.
Hello,
I had already read that post and found nothing usefull from it, asking for a code example is too much, i guess?
I had workedaround this by trashing the lookupedit and using a regular combo instead, its not what i wanted to do but at least works.
Hi,
Do you need to access a display value from a selected row or any value from this row? If the former, use the GridLookUpEdit.Properties.GetDisplayValueByKeyValue method. Pass a GridLookUpEdit.EditValue property value to this method.
C#object displayValue = gridLookUpEdit1.Properties.GetDisplayValueByKeyValue(gridLookUpEdit1.EditValue);
Visual BasicDim displayValue = GridLookUpEdit1.Properties.GetDisplayValueByKeyValue(GridLookUpEdit1.EditValue)
If you need to access any value, call the RepositoryItemGridLookUpEdit.GetRowByKeyValue method, pass a GridLookUpEdit.EditValue property value there. This method will return your row object. Cast it to your row object type to obtain necessary values.
C#object row = gridLookUpEdit1.Properties.GetRowByKeyValue(gridLookUpEdit1.EditValue); //cast to your type
Visual BasicDim row = GridLookUpEdit1.Properties.GetRowByKeyValue(GridLookUpEdit1.EditValue) 'cast to your type
If you are not successful with this task, please clarify what data source you assign to the GridLookUpEdit.
I look forward to your response.
Hello Svetlana,
Tyvm for your response and the code examples.
However this does not work, because i am using a RepositoryItemLookUpEdit inside an XtraGrid and this control does not provide neither the 'GetRowByKeyValue' method nor the 'EditValue' as you shown.
The closest i could get to the code you provided is this:
object row = repositoryItemLookUpEdit1.GetDataSourceRowByKeyValue(repositoryItemLookUpEdit1.EditValue);
// However, The Above line does not compile because the 'repositoryItemLookUpEdit' control does not provide an 'EditValue' property.
I want to get the 'repositoryItemLookUpEdit1' selected row of data to run validations.
While i was preparing an example project for you to try, i managed to get a workaround for my specific case of need:
private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
{
try
{
GridView view = sender as GridView;
GridColumn colCodTipe = view.Columns["Type"];
//Get the Value from the GridView
Object cellValue = view.GetRowCellValue(e.RowHandle, colCodTipe);
if (cellValue == System.DBNull.Value)
{
e.Valid = false;
view.SetColumnError(colCodTipe, "Mandatory Field!"); //<- Muestra el Error en la celda asociada.
}
//Get the selected Row of the LookupEdit:
MyTypeClass selectedrow = (MyTypeClass)repositoryItemLookUpEdit1.GetDataSourceRowByKeyValue(cellValue);
if (selectedrow.Code == 6)
{
//Do something…
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message + ex.StackTrace);
}
}
I attach an example project.
Other Answers
How to get the selected row of data from a RepositoryItemLookUpEdit control inside an xtraGrid.
C#private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
{
try
{
GridView view = sender as GridView;
GridColumn colCodTipe = view.Columns["Type"];
//Get Selected Value from the Grid's Column:
Object cellValue = view.GetRowCellValue(e.RowHandle, colCodTipe);
if (cellValue == System.DBNull.Value)
{
e.Valid = false;
view.SetColumnError(colCodTipe, "Mandatory Field!");
}
// Here I would like to retrieve the 'repositoryItemLookUpEdit' selected row of data
MyTypeClass selectedrow = (MyTypeClass)repositoryItemLookUpEdit1.GetDataSourceRowByKeyValue(cellValue);
if (selectedrow.Code == 6)
{
// //Do something...
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message + ex.StackTrace);
}
}
Hi,
Thank you for sharing your approach with us. Do not hesitate to contact us if you have any questions or concerns.