I have an application that allows a user to search a SQL database for a store. The user types in a store name and clicks a button and another, seperate form pops up with a list of stores that match the name that was entered. The user can select one of the stores and the popup form closes and a grid on the main form is populated with data from the database about that store. This is all powered through calling stored proceedures on the SQL server rather than using a dataset and it works without issue. The problem I have is when the user edits a cell in the grid.
I have a RowEditTemplate set up in modal for the grid because the stored procedure gives back more information than the user needs to see, and they are only allowed to edit a few of the fields that they can see. When they click on a cell, the RowEditTemplate pops up and they can make and save their changes. I've added code to the save button to call an update stored procedure and populate the paramters for the procedure. This all works fine as well.
The problem is that when the user searches for another store, then the RowEditTemplate no longer works! Even if they select the same store from the search box! I've stuffed a msgbox into BeforeRowEditTemplateDisplayed to let me know when it is called, and it is not called after the user performs their second search. I have the grid setup to show the RowEditTemplate when the cell changes (OnCellChange), but for some odd reason, it does not want to dispaly the template after the second search is performed by the user.
Any thoughts as to why this might be occuring?
I realized I left out some information in my original post. I'm using .NET Advantage 2008 Vol.2 CLR 2 on VB2005 (2.0 .NET Framework).
Also, I added another msgbox, so I now have a popup in both the BeforeEnterEditMode and BeforeRowEditTemplateDisplayed methods. The first time through the app, the BeforeRowEditTemplateDisplayed method fires, the template gets displayed, and then the BeforeEnterEditMode method fires. When the user searches for their second store (see my original post for details), *only* the BeforeEnterEditMode method fires!!!
This is really driving me crazy and I've already spent a few days trying to figure this out. Anyone, anyone at all have a direction they can point me in to help resolve this?!?!?!
Unfortunately it's really hard to say what might be going on based on your description. If the data source that the grid is bound to changes (and here I'm a little confused, since the grid must be bound to *something*), the RowEditTemplate should be closed automatically as it is no longer associated with a row that is being edited. You can best think of the RET as hosting all the grid's editors on another form, but strongly tied to the ActiveRow of the grid. It sounds like the grid either thinks that the template is already open, or somehow the template has become disassociated from the grid.
Your best bet is to submit a small sample to Developer Support so that they can look into it, or have a developer review the issue.
-Matt
Thanks Matt. Spent whole sunday to figure this out. Shold have come here first thing.
Thanks a million.
Matt, you are my savior! Assigning the RowEditTemplate in the grid's InitializeLayout event works perfectly.
Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you! Thank you for your brilliant insight!
I don't see why the DataMember property being null should matter, and I'm curious where you got a NullReferenceException when trying to access the RowEditTemplate (unless you were trying to access a property off of that). Perhaps what you could do is assign the RowEditTemplate to the band in the InitializeLayout event, which should fire each time to call SetDataBinding.
I did some more troubleshooting and checked the RowEditTemplateResolved as well. It too came up null after the second search. Stepping through the code to fill in the grid, I found that the reference to the template was lost when I bound the grid to the DataView. The code I use for this is: Me.u_grdStoreData.SetDataBinding(dv, Nothing, True)
The dv variable is the DataView. I picked this code up from another site that said it was better to do it this way than using the DataBind method. (Me.u_grdStoreData.DataBind()) because this way I could hide the columns that in the DataView that did match the schema of the grid.
Could that middle variable ("Nothing") be the issue?
Thanks again for the advice and opinion. I followed your suggestion about checking whether or not the band's RowEditTemplate was null or not and I found something interesting.
The first time the user searches and the grid is filled, the RowEditTemplate exists. The second time the grid is filled, I get NullReferenceException when trying to check for the RowEditTemplate on the band.
I don't really want to create the RowEditTemplate dynamically every time the grid is repopulated, but that looks like the most expedient solution at the moment. Any last thoughts before I submit a sample to Developer Support?