Ticket Q568239
Visible to All Users

Turning on editing capability on repository lookup editor for new row

created 11 years ago

I have a detail listing where a field is a lookup editor. We want the user to be able to select from the lookup list for a new row, but, for an existing, row not allow a change.

I assumed it would be easy to do this since I am trapping the new row event to initialize the data. However the new row event is fired after all the events associated with the in-place editor creation. I tried changing it after the editor was created, but that does not work.

I have a terrible kludge that gets what I want, but it would be nice if there was someway to know a new row was in process before the in-place edit form was created, so that the properties of the various editors on the form could be set.

I tried capturing key down to get the rowId of the row clicked assuming I could identify that the new row had been clicked before the editor was created. This does not seem to return the rowed that matches the system definition of a new row id.

Let me know if there is any combination of events I can use to set this if it is possible to do this in an in-place editor.

Thanks.

Answers approved by DevExpress Support

created 11 years ago (modified 11 years ago)

Hello,
You can do this by handling the GridView.ShowingEditor event:

C#
void gridView1_ShowingEditor(object sender, CancelEventArgs e) { GridView view = sender as GridView; e.Cancel = !view.IsNewItemRow(view.FocusedRowHandle); }

It disables editing for all existing rows but you will be able to edit a new item row. Is it exactly what you are looking for?
I hope to receive your response soon.

    Show previous comments (1)
    Andrew Ser (DevExpress Support) 11 years ago

      Hi,
      You can check a column in this event handler:

      C#
      void gridView1_ShowingEditor(object sender, CancelEventArgs e) { GridView view = sender as GridView; if (view.FocusedColumn.FieldName == "myColumnWithLookUp") e.Cancel = !view.IsNewItemRow(view.FocusedRowHandle); }

      I hope this helps. Drop me a line if you have other inquires.

        This only partially works. If you click directly on the field in the row, this works fine.
        If however you click on the row indicator which brings up the in-place edit form, it does not work. I tried putting this logic on the edit value changing event of the lookup editor, but the view is the editor not the row. I had tired something similar to this before by having the new row init event set a flag that this was new row processing. However that did not work since the init is fired after the editor screen is built. If I linked something to the edit value changing event, it was fired before the editor came up when the value was initialized, and then when changed. My solution was to take the event on and off of the editor. That works, but is a nasty kludge.
        I played some more with it, and have a solution that works other than one case. I set a flag to true indicating that this will be the initial set of the lookup edit value. I also set a flag when a new row is initiated. When you initiate a new row the edit value of the look up editor changes before the new row init event is fired. With the flag indicating that this is the first change, I do not stop the edit and set the flag to false to indicate that the next change will be blocked unless this is a new row. I set the flag to true when the edit form shows and the row is updated, so it gets set back to the initial after the creation/editing of each row.
        The new row init event fires, and sets the new row flag. The user can change the edit value of the lookup editor which is allowed since the new row flag is set.
        On an edit of a new row this works since the lookup editor edit value changes to set up the edit form, but when the user tries to change the edit value, the new row flag is not set, and the edit is cancelled.
        The one case that does not work, is when you try and edit the row a second time or edit the newly created row. The edit value of the lookup edit does not change on the set up of the editor, so the change flag does not get set to false, and the user can change the value. I have not been able to figure out a way to trap when the editor on the next entry has the same value as the prior entry.
        I tried capturing the row click to determine that the new row had been requested. This event does not fire if you click in the box to create a new row, which seems strange. It only fires when you click the indicator at the start of the row. However when you click the indicator, a new row is not created.
        What I really need is a way to determine that a new row is being created before the edit form is created and the look up edit value changed to initialize it.
        Let me know if there is a way to determine that a new row is requested before the various editor events are fired. It looks like the new row init event is fired after all of the editor set up for the form to enter the new row. I am sure you have your reasons for this, but it would be very nice to be able to know a new row is being created before all the editor setup is done.
        Please advise.
        Thanks.

        Andrew Ser (DevExpress Support) 11 years ago

          Hi,
          It is not quite clear how you show an edit form on clicking a row indicator. You said that it worked if you clicked directly a grid cell. However, the edit form cannot be shown if the GridView.OptionsBehavior.EditingMode property is Inplace or Default.
          To be honest, I've read your post several times but cannot imagine how a grid should operate in your case. There are things that are unclear:
           - How do you show the EditForm?
           - What is the goal of using RowIndicator?
           - Why do you need to initialize LookUpEdit's value on EditForm showing?
           - Initially you said that you wanted to disable editing for all cells of a certain column except for the NewItemRow. Do you want to do this in the EditForm? Would you please send us a sample that illustrates your scenario and describe your final goal in detail? If possible, attach a couple of screenshots to better explain the scenario.
          This information will allow us to find an appropriate solution faster.
          I hope to receive your response soon.

          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.