This is a migrated thread and some comments may be shown as answers.

add my own user control in a column

14 Answers 626 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Axel
Top achievements
Rank 1
Axel asked on 17 Oct 2011, 12:21 PM
Hello,
can I add my own user control in a column?
(RadGridView)
If so, can you show me an example?

Thanks

14 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 20 Oct 2011, 08:48 AM
Hello Axel,

Yes, you can add custom controls in a grid cell. However, we recommend using elements instead. Using controls may lead to performance loss and high memory consumption. In addition, you will experience visual glitches because controls cannot be clipped inside other controls efficiently in WinForms.  That is why our suite actively uses elements just like in WPF or Silverlight. This allows us also to support themes and animations. 

You can consider the following KB article which describes how to add radio button elements to a grid cell. Please describe in detail the desired look and behavior that you want to achieve and we will be glad to assist you further.

I am looking forward to your reply.
 
Kind regards,
Jack
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Axel
Top achievements
Rank 1
answered on 24 Oct 2011, 07:19 AM
Hello,
I have attached a picture of my UserControl.
This is to be inserted into a cell.
It will display dates in different colors. Furthermore, it has other futures.

When I look at the example radio button look at her.
Then there is a problem with "this.Children.Add (gridstatus)"
Gridstatus is a UserControl and not a RadElements

What can I do

Am thankful for every tip

addition:
I want to fill the UserControl "grid status" with a DataTable.
The DataTable I want to save again in a DataTable which I will bind to the grid.

0
Jack
Telerik team
answered on 24 Oct 2011, 11:03 AM
Hello Axel,

Thank you for writing me back and thank you for these details.

Like I said in my previous post, it is not recommended to use user controls in grid cells. That is why I pointed you to the radio button example. You could use elements to display custom data instead of a user control. This way your application will be faster and will look better. Another option will be to override the cell painting mechanism. Please take a look at the GridView >> Customize >> Custom Painting example in our demo application. It describes a similar scenario. 

I am not sure about the binding question, could you please describe it in detail?

Best wishes,
Jack
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Axel
Top achievements
Rank 1
answered on 25 Oct 2011, 08:21 AM
Hello,

you said
that it is not performing well enough to insert a UserControl. Can you show me an example anyway.

I've been looking at the example "GridView>> Customize>> Custom Painting." But that's not right for me.

Binding to Data:
I want to bind the grid to a DataTable.
A column of the DataTable is a DataTable as the Type.
And I would like to use this column to fill my UserControls.

That's the plan.
0
Jack
Telerik team
answered on 28 Oct 2011, 11:05 AM
Hi Axel,

Thank you for writing us back.

Your scenario seems to be similar to one of the hierarchy examples in our demo application. Could you please describe it with greater detail? I will be glad to help further.

The following sample demonstrates how to add a button control in a grid cell. You should replace the button with your custom control:
public class ButtonColumn : GridViewDataColumn
{
    public ButtonColumn(string fieldName)
        : base("ButtonColumn", fieldName)
    {
        Width = 100;
    }
 
    public override Type GetCellType(GridViewRowInfo row)
    {
        if (row is GridViewDataRowInfo)
        {
            return typeof(CustomCell);
        }
        return base.GetCellType(row);
    }
}
 
public class CustomCell : GridDataCellElement
{
    RadHostItem hostItem;
    RadButton button;
 
    public CustomCell(GridViewColumn column, GridRowElement row)
        : base(column, row)
    {}
 
    protected override void CreateChildElements()
    {
        button = new RadButton();
        button.Text = "Click me!";
        hostItem = new RadHostItem(button);
        this.Children.Add(hostItem);
    }
 
    public override bool IsCompatible(GridViewColumn data, object context)
    {
        return data.Name == "ButtonColumn" && context is GridDataRowElement;
    }
}

I hope this helps.
 
Best wishes,
Jack
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

0
Bao
Top achievements
Rank 1
answered on 19 Sep 2017, 11:03 PM

Hi Jack,

I have custom textbox when i do this way , it has problem with tabbing.

https://www.screencast.com/t/jO84luQcpt2

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 20 Sep 2017, 10:31 AM
Hello, Bao, 

Thank you for writing.  

Feel free to submit a support ticket where you can provide a sample project demonstrating the exact problem that you are facing. This would be appropriate way Telerik support to investigate the precise case and assist you further. 

Thank you for your understanding and cooperation.

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Gh Reza
Top achievements
Rank 1
answered on 18 Mar 2020, 10:31 PM

Hi Dear !

I want use this code in WinForm 2020 R1, but not works.

when add this control to my gridview, really nothing added to grid and closed property builder form.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 19 Mar 2020, 10:48 AM
Hello, Reza,

RadGridView allows you to create custom cell elements which contain the desired inner elements. The following help article demonstrates a step by step tutorial how to achieve it: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/creating-custom-cells 

A complete example is available in our Demo application >> GridView >> Columns example >> toggle the Custom checkbox on right Settings panel.

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Gh Reza
Top achievements
Rank 1
answered on 21 Mar 2020, 07:48 AM

Thank's for your support, But i have a problem with it.

In the following help article demonstrates a step by step tutorial how to achieve it: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/creating-custom-cells -> Extending the custom data cell example

Where defined  The "EventHandler radButtonElement_Click "?

0
Gh Reza
Top achievements
Rank 1
answered on 22 Mar 2020, 07:21 PM

Hi Dear !

I can only access to my custom cell in edit mode after adding row.How can I use my custom cell in radGridView New Row ?

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Mar 2020, 10:33 AM

Hello, Reza,

Indeed, the radButtonElement_Click event handler is not included in the provided code snippet. However, it is not expected to contain any solution specific code. It demonstrates how to subscribe to the Click event. It is up to you what action you will perform when clicking the button.

As to the question about the new row, note that in the custom GridViewDataColumn class, the GetCellType method is the appropriate place to specify what cell to be used for the respective data row. The referred example demonstrates how to replace only the cell element used in the GridViewDataRowInfo. If you want to replace the cells for other row as well, feel free to add an additional if condition for the GridViewNewRowInfo and return the type of the custom cell element that you have.  

The code snippet below shows how the same cell element is used for the data and new rows:

        public override Type GetCellType(GridViewRowInfo row)
        {
            if (row is GridViewDataRowInfo || row is GridViewNewRowInfo)
            {
                return typeof(GridDateTimeCellElement);
            }
            return base.GetCellType(row);
        }
I hope this information helps. 

 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Gh Reza
Top achievements
Rank 1
answered on 23 Mar 2020, 11:00 AM

Thank you.

It is worked. but i have another problem.

1- After adding new row , my custom cell value cleared.

2- How can i access to my custom Cell Value1 and Value2 and ...

(My Custom Cell contains an RadTextBoxElement and RadButtonElement )

    my custom cell has multiple values:

        1- Id (int) that must store in another cell . 

        2- Title (String) that must store in custom cell textbox.

        3-  an Object that may be use in some senario.

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 23 Mar 2020, 01:07 PM
 

Hello, Reza,

Note that due to the data virtualization that RadGridView offers, cell elements are created only for the currently visible cells and they are being reused during operations like scrolling, filtering, grouping etc. 

The SetContentCore method of the custom cell element is the appropriate place to extract the respective value from the data row (GridViewDataRowInfo) which is currently associated with this cell element: https://docs.telerik.com/devtools/winforms/knowledge-base/custom-gridview-cells-with-several-elements

Thus, whenever the cell element is being reused, the SetContentCore is called, the respective data is extracted from the currently associated data row and the correct information is displayed in the cell.

However, when you update the custom cell element's values, please don't forget to modify the value of the respective data cell. Thus, the SetContentCore method will extract the correct information the next time it is being called.

I believe that the provided information would be helpful for your scenario.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.

Tags
GridView
Asked by
Axel
Top achievements
Rank 1
Answers by
Jack
Telerik team
Axel
Top achievements
Rank 1
Bao
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Gh Reza
Top achievements
Rank 1
Share this question
or