We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

DataSourcing grid reimplementation

Thread ID:





31431 Jul 7,2005 09:30 AM Jul 11,2005 03:54 PM Windows Forms 21
Tags: GridControl
Martin Cyr
Asked On July 7, 2005 09:30 AM

Hi, As you suggested in your last post, I studied RepeaterUserControl sample. Pretty instructive to say the least. I think it gives a pretty nice idea of how to reimplement your grids structure (nice MVC structure btw). But now that I rewrote a grid to fit my needs (nested user control in cell in a cell embeded grid in a grid that is wrapped in another user control), I got a conceptual question. Where/how should I add DataSource to my grid. I need it to be accessible from the designer, so it''ll start from the wrapper user control, and I need the data in my OnDraw for the last cell that contains my final display user control. Should I simply pass it along the whole structure? If so, in the model, the control, the renderer? Or is there a more clever mechanism/interface I should use/implement?

Administrator [Syncfusion]
Replied On July 7, 2005 10:05 AM

If you need to get at it through the designer for your outer usercontrol, then it will have to be a public property of that class. And this suggests that this DataSource will not vary from cell to cell in any of the grids as there will only be a single property. If down where you need to know this datasource, you have knowledge of your ''inner'' usercontrol, then you could probably use the UserControl.Tag property to pass this DataSource from the outer UC.DataSource to the inner UC.Tag, and finally have it available in the OnDraw through the instance of the inner UC via its Tag property.

Martin Cyr
Replied On July 7, 2005 10:41 AM

That''s my problem, I don''t know how I should access the inner UC. I could declare it in the outter UC, but then I don''t know how to add it to the correct cell, or I can declare it in the cell, but then I don''t know how to access it from the outter UC. Just to make it more clear, here is a demo. On another subject, another problem I encountered is that the cell I selected from one of the inner grid cell gets a border in every other grid cell too.

Martin Cyr
Replied On July 7, 2005 11:23 AM

Sorry forgot to attach the demo... Silly me... or maybe not so much : "Web site found... Waiting for reply" I justed waited 5 mins for it, but it''s not loaded yet. Is there a problem with the site?

Martin Cyr
Replied On July 7, 2005 12:12 PM

My biggest problem, from what I understand, is that I seem to loose track of the parent when I create a cell embeded grid. I don''t know how to access the parent grid from the cells inside the cell embeded grid.

Administrator [Syncfusion]
Replied On July 7, 2005 12:49 PM

Are you parenting the embedded grid to the parent grid (ie, parentGrid.Controls.Add(embeddedGrid)? If so, you use embeddedGrid.Parent to get at the parentGrid. We have had soem glitches with uploads to our website this morning, but I think that has been corrected now.

Martin Cyr
Replied On July 7, 2005 02:12 PM

Just great, exactly what I wanted! But now that I can access the data, I realize that I might have a problem : is there a way that from the cells within the CellEmbededGrid, I could know the location of the CellEmbededGrid in it''s parent grid? Also, I need to know more about the conceptual approach. How should I provide the data to my UC? I can now access the data from the UC, but I want to do a nicer approach to providing data to my control. I could, from the OnDraw event, do like the RepeaterCell sample and simply call a function to put the data in the control, but I''d like it if I could create a more professionnal, reusable control. Less hard-coding, more flexibility.

Martin Cyr
Replied On July 7, 2005 02:44 PM

Btw, the upload script still doesn''t answer.

Martin Cyr
Replied On July 7, 2005 03:12 PM

I''m getting closer. I found some row/col info in the cellRenderer for the parent, but it only has the col/row of the selected cell (the active CellEmbededGrid), so I don''t know how to handle the inactive (static) control.

Martin Cyr
Replied On July 7, 2005 04:00 PM

Got it! Just adding two members in the parent renderer that holds row/col at OnDraw() wich I can then query in the CellEmbededGrid solves most of the problem. Now I realise that the parent renderer hasn''t finished the rendering job yet, so I get the old values, as if the parent renderer haven''t been called since the cell change, but the child renderer is still rendering. I tried to handle the CurrentCellChanged event in the parent grid, but it never seems to get fired, is it because I inherited from GridControl, is that wrong?

Martin Cyr
Replied On July 7, 2005 04:25 PM

I realized my mistake, CurrentCellChanged should''ve been CurrentCellActivated in the last post. But the problem is the same, the grid doesn''t seem to realise that the current cell has changed ie. the CurrentCell property on the grid doesn''t reflect the actual currently selected cell, I mean that when the CurrentCellActivated event gets fired, it''s still the old CurrentCell row and col that are reported.

Martin Cyr
Replied On July 7, 2005 04:42 PM

Wow, this is looking more and more like a novel. Anyways, I found that the event I was looking for is CurrentCellMoved, now the CurrentCell is the right one, but the OnDraw for the child grid cells is already done wrong. The values used in the OnDraw to identify the row/col are now good AFTER the CurrentCellMoved occurs but the draw happens before this update is made. I tried to refresh about every thing from the renderers to the cells to the grids, but no good. Also, when the form is minimized or scrolled too quick, the rendering stops working right. And I still can''t upload!

Administrator [Syncfusion]
Replied On July 7, 2005 06:34 PM

I am not sure I follow everything, but you want to know the parent grid''s row and col of the cell that holds the embedded grid when you are drawing cells in the embedded grid. Is this what you need? Try setting the row/col information into the embeddedgrid.TableStyle.Tag object. Then this values should then be available in any style.Tag object for any cell in the embedded grid in any method that gets a style object passed to it (like OnDraw).

Martin Cyr
Replied On July 8, 2005 08:58 AM

How should I set the tag? I mean where/when? I could do it in the parent cell renderer, but is it the best thing to do?

Martin Cyr
Replied On July 8, 2005 09:39 AM

If you''re suggesting that I should store a Point() structure in the tag of the cellembededgrid wich I would define in the renderer of the previous grid, then I tried that already. It works fine EXCEPT for the currently selected cell. From what I see, the parent grid renderer hasn''t been called yet when the inner grid renderer is called, so I still have the row/col values from the previously rendered cell.

Martin Cyr
Replied On July 8, 2005 10:03 AM

After closer inspection, correct me if I''m wrong, but I understand that when the current cell changes the following happens : the old cell is deselected and deactivated, then CurrentCellMoving, redrawn in its static state, then the new cell gets a OnDraw, but not the inner cell yet, the renderer rather goes back to the last cell, redraw it again (??? why ???) then the inner cell get drawn. But since the position is obtained from the parent renderer, I''m stuck with the position of the last drawn cell, wich is not the good one... And this time, since the upload script is fixed, I can show you what I mean!! Try moving around (oh and also try minimize/restore, what should I do to fix the refresh issue?) GridTest_689.zip

Administrator [Syncfusion]
Replied On July 8, 2005 10:07 AM

The cellrenderer.OnInitialize method should be called before you try drawing any part of the active cell. That method has the row/col passed into it. You could try saving these values at that point so they are available later when the active cell is drawn.

Martin Cyr
Replied On July 8, 2005 11:23 AM

Please check the project! I don''t know how the OnInitialize would be of any use to me. My problem seems to be caused by the OnDraw sequence with multiple layer of grids.

Administrator [Syncfusion]
Replied On July 8, 2005 01:30 PM

I worked with your project for a while, and have it working a little better by listening to the currentcellmoved event within the renderer class. Here are teh modified files back. http://www.syncfusion.com/Support/user/uploads/GridTest_c028842d.zip But it is not perfect. I think the main problem is that the PlanificationCellRenderer class does not have 2 embeddedgrids, one ot handle the static drawing and one ot handle the active drawing. In your embeddedgrid cell, you are trying to share instances of the cell control across many cells. If you want to do this, then you need a grid to handle the static drawing and a grid to handle the active drawing. You will notice in our sample where we did the GridInCell, we avoided this complication by having an new embeddedgrid instance for each cell that used this celltype. You are not doing this (and would not want to do this as you have many such cells).

Martin Cyr
Replied On July 11, 2005 08:40 AM

Wow! thanks for the help! I''ll keep on working from what you said... Again, THANKS! You definately provide the best support I EVER seen.

Martin Cyr
Replied On July 11, 2005 09:15 AM

About the resize/refresh, anytime one of those events are fired, only the currentcell gets redrawn in the top left corner of the form and the rest of the grid disapears. What''s happening?

Martin Cyr
Replied On July 11, 2005 03:54 PM

It''s ok, I fixed it. I rewrote the whole thing. Didn''t changed squat, but now the resize works and the selection change works too without the change you did. Sorry for making you work for nothing, but I still don''t even understand why it works now and it didn''t earlier. Perhaps it''s useless, but I''ll include the code, just in case it''s usefull to anyone. GridTest_2679.zip


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.