Hi,
I have an interesting scenario. I have a wingrid that displays records based on a search by the user with outlook groupby feature enabled. From the grid on double clicking a row i'm showing the details of the record in a windows form. I'm opening as a new form and not as a show dialog.
When the user double clicks the same row anytime.,i should not create another instance of the form, but i have to show the already opened instance. So if the instance is available i have to open the instance else i have to create a new instance.
To do this., i declared array of objects and resized the array with the row count of the grid. This is where the problem starts. I would pass the row index and open the instances like this.,
Array.Resize(ref obj, Grid.Rows.Count)
rowID = e.Row.Index;
obj[rowId] = new frmDetailsForm();
if(obj[rowID].IsDisposed !=true)
and show the existing window opened, else create a new instance.
Now., when there is a groupby in the grid, the row count is only groupby row count and i tend to miss the actual row count in the grid. My questions are,
1. How to track the available instances? (Might not be related to Ultragrid, still wanna clarify myself)
2. How to get the row index after the groupby is performed?
Thanks.,
Another similar option may be to use the row's ListIndex property, instead of its Index. The ListIndex property reflects the position of the row as it exists in the underlying data source, rather than as it exists in the grid row's containing collection. The benefit is that ListIndex is not updated when you sort or group, while Index is.
If you want to use ListIndex in this fashion, I'd recommend using a Dictionary<int,frmDetailsForm> object, instead of an array. Your key (an int) would store the ListIndex of the corresponding grid row, while your value (an instance of frmDetailsForm) would be the instance of your form. This way, you avoid needing to resize an array each time you add items, meaning that you no longer have to concern yourself about the grid's Rows.Count changing when you group/ungroup the grid. This also gives you a way to more easily track available instances, such as by iterating over the dictionary using a foreach loop.
Sorry for the late reply..
The scenario is that i have a search grid that displays the results. I have add screen (a new form with a grid in it) where users can add new items and upon saving i'm refreshing the search grid to display the newly added item.
User can double click the serach grid row to open the details of the item.One of my test cases is to open the item details and if they try to open the already existing item from the grid., i should NOT create a new instance, rather i should show the existing instance. This is where i used the dictionary to store the listindex and form isntance.
Now the question is, as i reload the search results., how can i get the list index of the newly added item?
Phew., pretty long., but i'm sure it is clear.