Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1800
Wingrid and windows form instances
posted

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();

 

When the user clicks again the same row., i'll check for the available instance.

 

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.,

  • 45049
    Suggested Answer
    posted

    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.

  • 469350
    Suggested Answer
    Offline posted

    Hi Viswanth,

    Once you group the grid, the rows become a hierarchy with GroupByRows at the top and data rows underneath. So there's no really good way to get a count of the rows.

    I think it would be more efficient for you to use a Dictionary<UltraGridRow, Form> for this, anyway. That way, you don't have to allocate memory for every row in the grid when the vast majority of them probably aren't being used at any given time.