Deleting markers

The markers located in the axis can be removed again using the RemoveMember method. In this sample the marker currently selected in the DataGrid is deleted. To do this the marker is first deleted from the axis, after which the row is deleted from the table.

private void btnDeleteXMarker_Click(object sender, EventArgs e)
{
    try
    {
        MarkerContainer ia = axisGroup.SubMember.OfType<MarkerContainer>().First();
        ia.RemoveMember(ia.SubMember.OfType<Marker>().Where(x => x.Orientation == TwinCAT.Measurement.Scope.API.CursorAlignment.Vertical).ToArray()[dataGridView1.SelectedCells[0].RowIndex]);
        dataGridView1.Rows.RemoveAt(dataGridView1.SelectedCells[0].RowIndex);
    }
    catch (Exception) { }
}

private void btnDeleteYMarker_Click(object sender, EventArgs e)
{
    try
    {
        MarkerContainer va = axisGroup.SubMember.OfType<MarkerContainer>().First();
        va.RemoveMember(va.SubMember.OfType<Marker>().Where(x => x.Orientation == TwinCAT.Measurement.Scope.API.CursorAlignment.Horizontal).ToArray()[dataGridView2.SelectedCells[0].RowIndex]);
        dataGridView2.Rows.RemoveAt(dataGridView2.SelectedCells[0].RowIndex);
    }
    catch (Exception) { }
}

The selection in the DataGridView can also be controlled by clicking on the marker in the chart.

To this end an EventHandler is registered to the member_Clicked event of the ChartPanel or ScopeProjectPanel. The selected model is handed over there so that it can continue to be used.

In the sample the matching index is sought in order to select the rows in the grid.

private void ChartPanel_Member_Clicked(object sender, TwinCAT.Measurement.ProjectBase.MeasurementMemberBase e)
{
    foreach(AxisGroup ag in chartPanel.ModelChart.SubMember.OfType<AxisGroup>())
    {
        foreach(MarkerContainer mc in ag.SubMember.OfType<MarkerContainer>())
        {
            if (mc.SubMember.Contains(e))
            {
                switch (((Marker)e).Orientation)
                {
                    case TwinCAT.Measurement.Scope.API.CursorAlignment.Vertical:
                        dataGridView1.ClearSelection();
                        dataGridView1[1, mc.SubMember.OfType<Marker>().Where(x => x.Orientation == TwinCAT.Measurement.Scope.API.CursorAlignment.Vertical).ToList().IndexOf(e as Marker)].Selected = true;
                        break;
                    case TwinCAT.Measurement.Scope.API.CursorAlignment.Horizontal:
                        dataGridView2.ClearSelection();
                        dataGridView2[0, mc.SubMember.OfType<Marker>().Where(x => x.Orientation == TwinCAT.Measurement.Scope.API.CursorAlignment.Horizontal).ToList().IndexOf(e as Marker)].Selected = true;
                        break;
                    default:
                        break;
                }
            }
        }
    }
}