The code here is to delete gmaproutes and markers based on the index given in my numericupdown box. When I have like 4 markers and gmaproutes , and I want to delete the 2nd gmaproute and marker, the 3rd gets connected to the 1st but the 4th is left unconnected with any other markers. How can I make all markers to be connected even after deleting a marker/gmaproute in between?
private void button4_Click(object sender, EventArgs e)
{
int row_index = (int)numericUpDown1.Value - 1;
if (row_index >= 0 && row_index < dt.Rows.Count)
{
dt.Rows.RemoveAt(row_index);
if (row_index < o.Markers.Count)
o.Markers.RemoveAt(row_index);
if (row_index < line_overlay.Routes.Count)
{
for (int i = line_overlay.Routes.Count - 1; i >= row_index; i--)
{
line_overlay.Routes.RemoveAt(i);
}
if (row_index > 0 && row_index < o.Markers.Count)
{
PointLatLng lastMarkerPos = o.Markers[row_index - 1].Position;
PointLatLng nextMarkerPos = o.Markers[row_index].Position;
GMapRoute newRoute = new GMapRoute(new List<PointLatLng>()
{
lastMarkerPos,
nextMarkerPos
}, "New Route");
newRoute.Stroke = new Pen(Brushes.Blue, 2);
line_overlay.Routes.Insert(row_index, newRoute);
}
}
}
for (int i = row_index; i < dt.Rows.Count; i++)
{
dt.Rows[i]["Marker"] = i + 1;
}
if (row_index > dt.Rows.Count)
{
row_index = dt.Rows.Count;
numericUpDown1.Value = row_index + 1;
}
if (dt.Rows.Count == 0)
{
ClearAll();
}
}
I tried adding another gmaproute with an index of row_index+1 but that doesn't seem to fix it