I have a wondering. I am using something called ZedGraphControl to draw a Graph. I have managed to do all this work, to draw a Graph out of different values.
The problem is that if I have drawed a graph and change some values and draw a Graph again, the previous Graph doesn´t dissapear from the diagram.
So what happens is that each time I press the button a new Graph is drawned to the diagram.

The function that do draw the Graph look like below where the last line: "myCurve =" is the line that draw the Graph.
I beleive I have to "delete" or refresh the GraphArea from Drawn lines.
I am really stuck and any idéas would be greatful.
I ex: tried to write myCurve.Clear(); but this didn´t have any effect.

void CreateGraph( ZedGraphControl ^z1 )
{
// Get a reference to the GraphPane instance in the ZedGraphControl
GraphPane ^myPane = z1->GraphPane;

// Generate a red curve 						
LineItem ^myCurve;
myCurve = myPane->AddCurve( L"Curve1", list, Color::Red, SymbolType::None );
}

Try redrawing the original graph with the same color as the background so that the lines will get erased, then draw the new graph.

Thanks. There might be 2 problems perheps if I try to do that.
The backgroundcolor of the diagram is going from ::Gray to LightGray:: so there is not one color.
For the line below, the code also attach some text to the diagram "Curve1" so this text adds each time I press the button. So it seems that a line and the text just adds for each buttonpress.

LineItem ^myCurve;
myCurve = myPane->AddCurve( L"Curve1", list, Color::Red, SymbolType::None );

What I had in mind but are not sure is that if there is any method to Clear() everyting in the diagramcontrol as you do for a textBox ex: textBox1->Text = "". The control is called zg1 but I cant find any ->Clear() members or ->Delete().
I tried to write zg1->Invalidate(); but this did not help.

The function is written like this if this gives any help:
I know this isn´t a standardItem in the C++ toolBox but I give it a try.

void CreateGraph( ZedGraphControl ^z1 )
{
}

Try redrawing the original graph with the same color as the background so that the lines will get erased, then draw the new graph.

For the line below, the code also attach some text to the diagram "Curve1" so this text adds each time I press the button. So it seems that a line and the text just adds for each buttonpress.

LineItem ^myCurve;
myCurve = myPane->AddCurve( L"Curve1", list, Color::Red, SymbolType::None );

Yes, AddCurve() adds a new curve (and the related title to graph's legend) as its name implies.

What I had in mind but are not sure is that if there is any method to Clear() everyting in the diagramcontrol as you do for a textBox ex: textBox1->Text = "". The control is called zg1 but I cant find any ->Clear() members or ->Delete().

Related to that ...

// remove all curves
while(z1->GraphPane->CurveList->Count > 0)
    z1->GraphPane->CurveList->Remove(z1->GraphPane->CurveList[0]);
// ... now you need to add at least one curve to have something
// displayed
// remove a specific curve
CurveItem ^ remove = z1->GraphPane->CurveList["name_of_the_curve"];
if(remove)  // does it exist?
    z1->GraphPane->CurveList->Remove(remove);
// instead of removing/clearing curves,
// a light-weight method is to modify the curve's list directly
CurveItem ^ curve = z1->GraphPane->CurveList["name_of_the_curve"];
if(curve)
{
    // try accessing the list
    IPointListEdit ^list = dynamic_cast<IPointListEdit ^>(curve->Points);

    if(list)
    {
        // throw away all current values
        list->Clear();

        // ... and add some new
        for ( int i = 0; i < 36; i++ )
        {
            double x = (double)i * 5.0;
            double y = Math::Sin( (double)i * Math::PI / 15.0 ) * 16.0;
            double y2 = y * 13.5;

            list->Add( x, y );
        }

        // depending on what you actually changed in the graph, you
        // might need to call AxisChange() ...
        // z1->AxisChange();

        // redraw the graph
        z1->Refresh();
    }
}

Great thanks! This worked. I will play a bit with this code.

/J

One more method to remove all curves is ...

z1->GraphPane->CurveList->Clear();
This question has already been answered. Start a new discussion instead.