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

Help with waiting bar in radgridview

3 Answers 153 Views
GridView
This is a migrated thread and some comments may be shown as answers.
calca
Top achievements
Rank 1
calca asked on 03 Jun 2013, 04:15 PM
Hi, im trying to use waiting bars inside radgridview, I sucessfully add the waitingbars to the gridview in the CellFormatting event.
The problems comes when i try to dinamically change the state of the waitingbars individually (startwaiting - stopwaiting) when certain event happend eg. when i click a button i want determined cell to starwaiting or stopwaiting, here is the button code:        

private void NewPjButton_Click(object sender, EventArgs e)
{
    radGridView1.EndEdit();
    radGridView1.Rows[2].Cells[5].IsSelected = true;
    radGridView1.Rows[2].Cells[5].BeginEdit();
 
    RadwaitingBarEditor editor = radGridView1.ActiveEditor as RadwaitingBarEditor;
 
    if (editor != null) //this is always null
    {
        RadwaitingBarEditorElement element = editor.EditorElement as RadwaitingBarEditorElement;
        element.StartWaiting();
    }
}

and here the editor and element editor:

public class RadwaitingBarEditor : BaseGridEditor
{
    public override void BeginEdit()
    {
        base.BeginEdit();
        this.EditorElement.Focus();
        ((RadwaitingBarEditorElement)this.EditorElement).WaitingStarted += new EventHandler(RadwaitingBarEditor_WaitingStarted);
    }
    public override bool EndEdit()
    {
        ((RadwaitingBarEditorElement)this.EditorElement).WaitingStarted -= new EventHandler(RadwaitingBarEditor_WaitingStarted);
        return base.EndEdit();
    }
    void RadwaitingBarEditor_WaitingStarted(object sender, EventArgs e)
    {
        OnValueChanged();
    }
    protected override RadElement CreateEditorElement()
    {
        return new RadwaitingBarEditorElement();
    }
}
 
public class RadwaitingBarEditorElement : RadWaitingBarElement
{
    public RadwaitingBarEditorElement()
    {
        this.CanFocus = true;
         
    }
    public event EventHandler WaitingStarted;
    protected override Type ThemeEffectiveType
    {
        get
        {
            return typeof(RadWaitingBarElement);
        }
    }
   protected override void OnPropertyChanged(RadPropertyChangedEventArgs e)
    {
        base.OnPropertyChanged(e);
        if (e.Property == RadTrackBarItem.ValueProperty
            && this.Parent != null
            && this.WaitingStarted != null)
        {
            this.WaitingStarted(this, EventArgs.Empty);
        }
    }
}

this code just dosent work, the editor is always null. Please if someone can guide me how to do it correctly I will apreciate it so much!!.

Thank you, 

3 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Petrov
Telerik team
answered on 06 Jun 2013, 09:45 AM
Hello,

Thank you for writing.

To achieve what you want you should not use an editor. Editors are used for editing the value of a particular cell and you cannot use a waiting bar to edit a value as it is a control strictly for display purposes. Also it is not advisable to add/remove elements inside the CellFormatting event.

The best approach in your case would be to create a custom column with custom cells. This will allow you to control more precisely which items "are waiting" and start and stop the waiting bars easier.

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

Regards,
Ivan Petrov
Telerik
RadChart for WinForms is obsolete. Now what?
0
calca
Top achievements
Rank 1
answered on 07 Jun 2013, 08:40 PM
Hi Ivan,

Thanks to you I was able to do exactly what I wanted to, however I have a question about this method you show me.
I'm making the changes in the control here: 

protected override void SetContentCore(object value)
{
    if (this.Value.ToString() == "1")
    {
        this.radWaitingBarElement.TextElement.ForeColor = Color.Red;
        this.radWaitingBarElement.TextElement.Text = "Processing...";
        this.radWaitingBarElement.StartWaiting();
    }
    if (this.Value.ToString() == "0")
    {
        this.radWaitingBarElement.TextElement.ForeColor = Color.Green;
        this.radWaitingBarElement.TextElement.Text = "Successfull";
        this.radWaitingBarElement.StopWaiting();
    }
}

this is in the custom class I created for the control and I make those change via the Value property of the cells from my main program, this works just fine, but is this the best approach to make those kind of change? or there is another and better way to do it?


Thanks for the help!!
0
Ivan Petrov
Telerik team
answered on 12 Jun 2013, 06:16 PM
Hello,

Thank you for writing back.

This is the best approach in your case. The data elements have no reference to the visual elements of RadGridView. Each visual element has a reference to the data (logical) item it is displaying and tracks any changes in the data item. This is the way to communicate any changes from the data item to the visual element. 

I hope this helps. Do not hesitate to write back with further questions.

Regards,
Ivan Petrov
Telerik
RadChart for WinForms is obsolete. Now what?
Tags
GridView
Asked by
calca
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
calca
Top achievements
Rank 1
Share this question
or