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

Help with Creating Progress Bar column

7 Answers 372 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 03 Aug 2011, 05:54 AM
First off, I'd like to mention that I am a complete noob when it comes to C#. It's a steep hill to climb. :)

In any case, I'm creating an addin class for Microsoft Dynamics NAV, that will display a list of data using the Telerik gridview control. In one of those columns I'd like to show a progress bar. I've seen how you can add code to the cell formatting event trigger, but I don't know how to do that when I do not have an interface in my solution. All the examples I've seen reference form controls.

Any help is extremely appreciated. For reference, this is my code below. It works great for what i need with exception of the progress bar column. the grid is being populated from teh contents of a published web service.

namespace AddInSamples
{
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Microsoft.Dynamics.Framework.UI.Extensibility;
    using Microsoft.Dynamics.Framework.UI.Extensibility.WinForms;
    using Telerik.WinControls;
    using Telerik.WinControls.UI;
    using WorkCenterRef;
 
    [ControlAddInExport("WorkCenterStatusListTelerik")]
    public class StaticNoCaptionAddIn : WinFormsControlAddInBase
    {
        private WorkCenterRef.WorkCenter_Service workCenterList;
        private WorkCenterRef.WorkCenter[] workCenters;
 
        private Telerik.WinControls.UI.RadGridView dataGrid;
 
        protected override Control CreateControl()
        {
            dataGrid = new RadGridView();
 
            GridViewTextBoxColumn column1 = new GridViewTextBoxColumn("No.");
            GridViewTextBoxColumn column2 = new GridViewTextBoxColumn("Name");
            GridViewDecimalColumn column3 = new GridViewDecimalColumn("% Capacity");
            GridViewTextBoxColumn column4 = new GridViewTextBoxColumn("ProgressBar");
 
            column4.DataType = typeof(int);
 
            column1.Width = 100;
            column2.Width = 100;
            column3.Width = 100;
            column4.Width = 100;
 
            this.dataGrid.Columns.Add(column1);
            this.dataGrid.Columns.Add(column2);
            this.dataGrid.Columns.Add(column3);
            this.dataGrid.Columns.Add(column4);
 
            workCenterList = new WorkCenter_Service();
            workCenterList.UseDefaultCredentials = true;
            workCenters = workCenterList.ReadMultiple(null, null, 0);
 
            this.dataGrid.TableElement.BeginUpdate();
 
            this.dataGrid.AllowAddNewRow = false;
            this.dataGrid.AllowDeleteRow = false;
            this.dataGrid.AllowEditRow = false;
            this.dataGrid.AllowDragToGroup = false;
 
            column4.ReadOnly = true;
 
            foreach (WorkCenterRef.WorkCenter workCenter in workCenters)
            {
                this.dataGrid.Rows.Add(workCenter.No, workCenter.Name, workCenter.Percent_Capacity);               
            }
 
            this.dataGrid.TableElement.EndUpdate();
             
            return dataGrid;
        }
 
        /// <summary>
        /// Gets a values indicating whether the control shall show a caption.
        /// Overrides the implementation of StringControlAddInBase for IWinFormsControlAddIn.AllowCaptionControl
        /// </summary>
        public override bool AllowCaptionControl
        {
            get
            {
                return false;
            }
        }
    }
}

7 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 05 Aug 2011, 06:51 AM
Hi Michael,

Thank you for writing and for the code snippet.

The best way to add a column with RadProgressBars to the RadGridView is using a custom column with custom cells. You can refer to the following help article which demonstrates how to add a progress bar column to the grid: Creating custom cells.

I hope this will help you. If you have further questions, I would be glad to help.

All the best,
Ivan Petrov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
0
Reyniel
Top achievements
Rank 1
answered on 04 Dec 2012, 02:55 AM
Hi Ivan,

thank you for the link on how to create a progress bar column,
another thing is how to set the Label for the progress bar inside the row?
Like for the regular progressbar you can just access it by using the .Text method, how can i simply do that in the progressbar column?

Thanks in advance.
0
Ivan Petrov
Telerik team
answered on 06 Dec 2012, 03:04 PM
Hello Reyniel,

Thank you for writing.

In the example RadProgressBarElement is added to the cells. To change the text of the progress bar element you can access its TextElement and set the text to its Text property. You can use the SetContentCore method from the example to change the text.

I hope this is useful. Feel free to write back with any further questions.

Kind regards,
Ivan Petrov
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
0
Maulik
Top achievements
Rank 1
answered on 25 Apr 2016, 09:56 AM

Hi Ivan,

Creating Custom cells Helped me creating new column with progress bar. 

But I stuck on how to change the min and max value of progress bar. 

Can you please help me with this issue ? 

Thanks 

Maulik Panchal

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Apr 2016, 12:00 PM
Hello Maulik,

Thank you for writing.

In the CreateChildElements of the ProgressBarCellElement you can specify the Minimum and Maximum properties of the RadProgressBarElement:
private RadProgressBarElement radProgressBarElement;
 
protected override void CreateChildElements()
{
    base.CreateChildElements();
 
    radProgressBarElement = new RadProgressBarElement();
    radProgressBarElement.Minimum = 0;
    radProgressBarElement.Maximum = 10;
    this.Children.Add(radProgressBarElement);
}

I hope this information helps. Should you have further questions I would be glad to help.

 Regards,
Dess
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Tamás
Top achievements
Rank 1
answered on 21 May 2020, 04:36 PM

Hi All!

So i created the progressbar custom column and added to my radgridview successfully. All data is comming from an entity framework query and at the last step i am inserting the column to the right position. Unfortunately i do not know how to set value for the progressbar inside the cell... 

Can you give me a hint? 

Thanks!

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 26 May 2020, 09:29 AM

Hello, Tamás,   

I would recommend you to have a look at the following help article: https://docs.telerik.com/devtools/winforms/controls/gridview/cells/creating-custom-cells 

The SetContentCore method of the custom cell is the appropriate place to synchronize the cell's Value with the value of the inner elements, e.g. RadProgressBarElement in this case. In case the cell's Value doesn't actually store the numeric value, you can extract it from the RowInfo.DataBoundItem.  

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

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
Michael
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Reyniel
Top achievements
Rank 1
Maulik
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Tamás
Top achievements
Rank 1
Share this question
or