int mark_data = 0; //被选中的数据 /// <summary> /// 对列表数据进行检查,不正常时进行提示 /// </summary> /// <returns></returns> private Byte Check_data() { Byte check_right = 0; byte mark_error = 0; if (numcount < 2) //判断一下数据是不是合适 { if (numcount == 0) { MessageBox.Show("列表中没有数据项"); mark_error = 1; } else if (mark_data == 0) { MessageBox.Show("列表中的数据项只有一向"); mark_error = 1; } } else { for (Byte i = 0; i < numcount; i++) { if (XiangMuList.GetItemChecked(i)) { if (check_right == 0) { check_right = 1; mark_data = i; } else { MessageBox.Show("不能同时选中多项"); mark_error = 1; check_right = 0; mark_data = 0; } } } } if (check_right == 1) { MessageBox.Show("选中了第" + mark_data.ToString() + "项"); } else if (mark_error == 0) { MessageBox.Show("没有选中的项目"); mark_error = 1; } return(mark_error); }
/// <summary> /// 删除选中项 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button6_Click(object sender, EventArgs e) { if (Check_data() == 0) { for (int i = XiangMuList.Items.Count - 1; i > -1; i--) { if (XiangMuList.GetItemChecked(i)) { XiangMuList.Items.RemoveAt(i); Lat_posion[i] = 9999;//清除的变量暂时标记一下 Lng_posion[i] = 9999; } } Byte counta = 0; Byte con_aa = 0; for (int i = 0; i <= XiangMuList.Items.Count + 2; i++) { if (Lat_posion[i] != 9999 && Lng_posion[i] != 9999) { Lat_posion[counta] = Lat_posion[i]; Lng_posion[counta] = Lng_posion[i]; counta++; } } for (int i = 0; i < counta + 3; i++) { if (Lat_posion[i] != 0) { con_aa++; } } for (int i = XiangMuList.Items.Count - 1; i > -1; i--) { XiangMuList.Items.RemoveAt(i); } numcount = 0; top.Markers.Clear(); top.Routes.Clear(); PointLatLng p = new PointLatLng(); PointLatLng p_last = new PointLatLng(); for (int i = 0; i < con_aa; i++) { p.Lat = Lat_posion[i]; p.Lng = Lng_posion[i]; currentMarker = new GMarkerGoogle(p, GMarkerGoogleType.arrow); currentMarker.ToolTipText = (i + 1).ToString(); currentMarker.ToolTipMode = MarkerTooltipMode.Always; //currentMarker.IsHitTestVisible = false; top.Markers.Add(currentMarker); numcount++; if (i > 0) { p_last.Lat = Lat_posion[i - 1]; p_last.Lng = Lng_posion[i - 1]; DrawLineBetweenTwoPoint(p, p_last); } XiangMuList.Items.Add("第" + numcount.ToString() + "目标点" + " J:" + currentMarker.Position.Lat.ToString() + " W:" + currentMarker.Position.Lng.ToString()); } } }