-2

I have some problem with coding on C# with data from dataGridView.

I have some data table on dataGridView and I need to put this info into gMapControl using GMap.Net for creating of several markers on the map.

Here is my code:

private void gMapControl1_Load(object sender, EventArgs e)
{
    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
    GMap.NET.WindowsForms.GMapOverlay markersOverlay = new GMap.NET.WindowsForms.GMapOverlay(gMapControl1, "marker");
    GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen marker =
        new GMap.NET.WindowsForms.Markers.GMapMarkerGoogleGreen(
        new GMap.NET.PointLatLng(MyVar.lat, MyVar.lon));

    gMapControl1.Position = new GMap.NET.PointLatLng(MyVar.lat, MyVar.lon);

    marker.ToolTip = new GMap.NET.WindowsForms.ToolTips.GMapRoundedToolTip(marker);
    marker.ToolTipText = "Home";
    markersOverlay.Markers.Add(marker); 
    gMapControl1.Overlays.Add(markersOverlay);
}
Cache Staheli
  • 3,510
  • 7
  • 32
  • 51
Vitaliy
  • 1
  • 1
  • In datagridview I have coordinate list. I have trying to create a several markers on map using GMap. – Vitaliy Feb 03 '17 at 21:50
  • have you tried anything in terms of getting the values out of the datagridview? – Simon Price Feb 03 '17 at 21:50
  • On Form1 with private void gMapControl1_Load i can create a circle "for" for adding markers to markersOverlay. But I need to use coordinates from datagridview from another Form2. – Vitaliy Feb 03 '17 at 21:53
  • ok, so i understand you have a datagridview and it has data in it, what have you tried in order to get the data out. Please edit your question to show what you have done in order to access the cell values – Simon Price Feb 03 '17 at 21:59
  • In datagridview I have table with Name, coordinates and some additional information, but I need to use only coordination from datagridview. – Vitaliy Feb 03 '17 at 21:59
  • see my answer below that should get you going – Simon Price Feb 03 '17 at 22:02
  • When I create on Form1 gMapControl1 and datagridview, I don't have any problems. But my datagridview placed on Form2 and gMapControl1 placed on Form1. As a result, I want to placed on map several markers. – Vitaliy Feb 03 '17 at 22:03
  • 1
    im voting to close this question as too low quality. I have asked the same quesion in a few different ways now and your not able to help me to help you – Simon Price Feb 03 '17 at 22:04

2 Answers2

0

This is pseudo code, that should get you going

var dgv = new DataGridView();
var str = dgv.Rows[0].Cells["Column Name here"]; //column name
var ord = dgv.Rows[0].Cells[0]; //column ordnal 

var changeableValue = string.Empty;
foreach (DataGridViewRow row in dgv.Rows)
{
    changeableValue = row.Cells[0].ToString(); // ordinal position again
}
Simon Price
  • 3,011
  • 3
  • 34
  • 98
0
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
    
    GMapControl1.DragButton = Windows.Forms.MouseButtons.Left
    GMapControl1.CanDragMap = True

    If RadioButton1.Checked Then
        ' Form3.GMapControl1.MapProvider = GMapProviders.GoogleSatelliteMap
        Form3.GMapControl1.MapProvider = GMapProviders.GoogleHybridMap
    ElseIf RadioButton2.Checked Then
        Form3.GMapControl1.MapProvider = GMapProviders.GoogleMap
    ElseIf RadioButton3.Checked Then
        Form3.GMapControl1.MapProvider = GMapProviders.GoogleTerrainMap
    End If

    Form3.GMapControl1.Position = New PointLatLng(35.502509, 2.916693)
    Form3.GMapControl1.MinZoom = 0
    Form3.GMapControl1.MaxZoom = 24
    Form3.GMapControl1.Zoom = 7
    Form3.GMapControl1.Dock = DockStyle.Fill
    'GMapControl1.AutoScroll = True

    GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache


    For j As Integer = 0 To DataGridView1.Rows.Count - 2

        Dim marker As GMarkerGoogle = New GMarkerGoogle(New PointLatLng(DataGridView1.Rows(j).Cells(1).Value, DataGridView1.Rows(j).Cells(2).Value), GMarkerGoogleType.green)

        ' marker.ToolTipText = String.Format("réservoir " + DataGridView1.Rows(j).Cells(4).Value)
        marker.ToolTipText = String.Format("Réservoir " + DataGridView1.Rows(j).Cells(8).Value + " m3 " + DataGridView1.Rows(j).Cells(4).Value)
        markers.Markers.Add(marker)
        Form3.GMapControl1.Overlays.Add(markers)
        marker.ToolTipMode = MarkerTooltipMode.Always
    Next
    Return
End Sub
Joe Mayo
  • 7,501
  • 7
  • 41
  • 60