User Control DataGridColumnStyle

G

Guest

I'm trying to create a DataGridColumnStyle that uses a user control in a WinForm app. The .Net documentation says this can be done, but there are no instructions on HOW to do it

I've seen example and have succeeded in creating a combobox ColumnStyle and Icon ColumnStyle - but can't seem to manage a custom user control. In the case of the icon the Paint functions draws the bitmap. In the case of the combobox the Paint function draws a text string, and the Edit function repositions a ComboBox and makes it visible over the cell

But I want the user controls to be visible whenever the cell is visible. So I can't use a single control and just reposition it. Instead I created an array of the user controls, and am trying to display them in the Paint function. But I either get a transparent cell (see all the way through the window to the app below), or a blank cell. I've tried calling the controls .Show and it's .Invalidate methods, and I've also called it .BringToFront - but so far no luck

Any help/suggestions would be greatly appreciated

Below is my Paint function. ucTestPanel is my user control, and Fields is my ArrayList of user controls. Note that I've taken out and put back in all the Show, Invalidate, CreateControl calls, but it doesn't seem to make a difference

Thanks

Gart

protected override void Paint (Graphics g, Rectangle Bounds, CurrencyManager Source, int RowNum, Brush BackBrush, Brush ForeBrush, bool AlignToRight

tr

ucTestPanel Field

if (Fields.Count <= RowNum

Field = new ucTestPanel()
Field.Bounds = Bounds
Field.Visible = true
Field.Value = "Junk"
Fields.Add (Field)

els

Field = (ucTestPanel)Fields[RowNum]


((ucTestPanel)Fields[RowNum]).CreateControl()
((ucTestPanel)Fields[RowNum]).BringToFront()
((ucTestPanel)Fields[RowNum]).Show()
((ucTestPanel)Fields[RowNum]).Invalidate()

catch (System.Exception exc

HandleError ("Error in DataGridTestPanel.Paint", exc)
 
G

Guest

Sorry to reply to my own post, but I figured it out. I had to create the user controls *before* Paint got called. There's another method which is called by the environment to add the controls to the DataGrid's controls collection, and this is called before any Paint's are called

Garth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top