Ticket T220480
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

RepositoryItemGridLookUpEdit - How to get a selected row's column value

GridLookUpEdit - How to Retrieve the Value Corresponding to the Currently Selected Display Value?

created 10 years ago

[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???

Answers approved by DevExpress Support

created 10 years ago

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.

    Comments (3)

      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.

      DevExpress Support Team 10 years ago

        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 Basic
        Dim 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 Basic
        Dim 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

          created 10 years ago (modified 10 years ago)

          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); } }
            Comments (1)
            DevExpress Support Team 10 years ago

              Hi,

              Thank you for sharing your approach with us. Do not hesitate to contact us if you have any questions or concerns.

              Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

              Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.