Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8987949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:54:45+00:00 2026-06-15T21:54:45+00:00

Hello I am trying to work on a project where the application opens .csv

  • 0

Hello I am trying to work on a project where the application opens .csv file and read data from it and shows different point in a static map. I also would like to add an option for users to add latitude, longitude etc in the data list. Listview in the application appears only when a .csv file is opened. But I am having difficulty adding new gps point to the .csv file. my codes are given here

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace CourseworkExample
{
    public partial class Form1 : Form
    {
        public GPSDataPoint gpsdp;
        List<GPSDataPoint> data;
        List<PictureBox> pictures;
        List<TabPage> tabs;
        public static int pn = 0;
        private TabPage currentComponent;
        private Bitmap bmp1;
        string[] symbols = {  "hospital", "university" };
        Image[] symbolImages;
        ListBox lb = new ListBox();

        public Form1()
        {
            InitializeComponent();
            data = new List<GPSDataPoint>();
            pictures = new List<PictureBox>();
            tabs = new List<TabPage>();
            symbolImages = new Image[symbols.Length];
            for (int i = 0; i < 2; i++)
            {
                string location = "data/" + symbols[i] + ".png";
                symbolImages[i] = Image.FromFile(location);

            }
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FileDialog ofd = new OpenFileDialog();
            string filter = "CSV File (*.csv)|*.csv";
            ofd.Filter = filter;
            DialogResult dr = ofd.ShowDialog();
            if (dr.Equals(DialogResult.OK))
            {
                int i = ofd.FileName.LastIndexOf("\\");

                string name = ofd.FileName;
                string path = ofd.FileName;
                if (i > 0)
                {
                    name = ofd.FileName.Substring(i + 1);
                    path = ofd.FileName.Substring(0, i + 1);
                }
                TextReader input = new StreamReader(ofd.FileName);
                string mapName = input.ReadLine();
                GPSDataPoint gpsD = new GPSDataPoint();
                gpsD.setBounds(input.ReadLine());
                string s;
                while ((s = input.ReadLine()) != null)
                {
                    gpsD.addWaypoint(s);
                }
                input.Close();
                TabPage tabPage = new TabPage();
                tabPage.Location = new System.Drawing.Point(4, 22);
                tabPage.Name = "tabPage" + pn;
                ListBox lb = new ListBox();
                lb.Width = 300;
                int selectedindex = lb.SelectedIndex;


                lb.Items.Add(mapName);
                lb.Items.Add("Bounds");
                lb.Items.Add(gpsD.Bounds[0] + " " + gpsD.Bounds[1] + " " + gpsD.Bounds[2] + " " + gpsD.Bounds[3]);
                lb.Items.Add("Waypoint");
                foreach (WayPoint wp in gpsD.DataList)
                {
                    lb.Items.Add(wp.Name + " " + wp.Latitude + " " + wp.Longitude + " " + wp.Ele + " " + wp.Sym);
                }
                tabPage.Controls.Add(lb);
                pn++;
                tabPage.Padding = new System.Windows.Forms.Padding(3);
                tabPage.Size = new System.Drawing.Size(192, 74);
                tabPage.TabIndex = 0;
                tabPage.Text = name;
                tabPage.UseVisualStyleBackColor = true;
                tabs.Add(tabPage);
                tabControl1.Controls.Add(tabPage);
                tabPage = new TabPage();
                tabPage.Location = new System.Drawing.Point(4, 22);
                tabPage.Name = "tabPage" + pn;
                pn++;
                tabPage.Padding = new System.Windows.Forms.Padding(3);
                tabPage.Size = new System.Drawing.Size(192, 74);
                tabPage.TabIndex = 0;
                tabPage.Text = mapName;
                string location = path + mapName;
                tabPage.UseVisualStyleBackColor = true;
                tabs.Add(tabPage);
                PictureBox pb = new PictureBox();
                pb.Name = "pictureBox" + pn;
                pb.Image = Image.FromFile(location);
                tabControl2.Controls.Add(tabPage);
                pb.Width = pb.Image.Width;
                pb.Height = pb.Image.Height;
                tabPage.Controls.Add(pb);
                currentComponent = tabPage;
                tabPage.Width = pb.Width;
                tabPage.Height = pb.Height;
                pn++;
                tabControl2.Width = pb.Width;
                tabControl2.Height = pb.Height;
                bmp1 = (Bitmap)pb.Image;
                int lx, ly;
                float realWidth = gpsD.Bounds[1] - gpsD.Bounds[3];
                float imageW = pb.Image.Width;
                float dx = imageW * (gpsD.Bounds[1] - gpsD.getWayPoint(0).Longitude) / realWidth;
                float realHeight = gpsD.Bounds[0] - gpsD.Bounds[2];
                float imageH = pb.Image.Height;
                float dy = imageH * (gpsD.Bounds[0] - gpsD.getWayPoint(0).Latitude) / realHeight;
                lx = (int)dx;
                ly = (int)dy;

                using (Graphics g = Graphics.FromImage(bmp1))
                {
                    Rectangle rect = new Rectangle(lx, ly, 20, 20);
                    if (gpsD.getWayPoint(0).Sym.Equals(""))
                    {
                        g.DrawRectangle(new Pen(Color.Red), rect);
                    }
                    else
                    {
                        if (gpsD.getWayPoint(0).Sym.Equals("hospital"))
                        {
                            g.DrawImage(symbolImages[0], rect);
                        }
                        else
                        {
                            if (gpsD.getWayPoint(0).Sym.Equals("university"))
                            {
                                g.DrawImage(symbolImages[1], rect);
                            }
                        }
                    }
                }
                pb.Image = bmp1;
                pb.Invalidate();

            }
        }

        private void openToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            FileDialog ofd = new OpenFileDialog();
            string filter = "CSV File (*.csv)|*.csv";
            ofd.Filter = filter;
            DialogResult dr = ofd.ShowDialog();
            if (dr.Equals(DialogResult.OK))
            {
                int i = ofd.FileName.LastIndexOf("\\");

                string name = ofd.FileName;
                string path = ofd.FileName;
                if (i > 0)
                {
                    name = ofd.FileName.Substring(i + 1);
                    path = ofd.FileName.Substring(0, i + 1);
                }
                TextReader input = new StreamReader(ofd.FileName);
                string mapName = input.ReadLine();
                GPSDataPoint gpsD = new GPSDataPoint();
                gpsD.setBounds(input.ReadLine());
                string s;
                while ((s = input.ReadLine()) != null)
                {
                    gpsD.addWaypoint(s);
                }
                input.Close();
                TabPage tabPage = new TabPage();
                tabPage.Location = new System.Drawing.Point(4, 22);
                tabPage.Name = "tabPage" + pn;
                ListBox lb = new ListBox();
                lb.Width = 300;
                lb.Items.Add(mapName);
                lb.Items.Add("Bounds");
                lb.Items.Add(gpsD.Bounds[0] + " " + gpsD.Bounds[1] + " " + gpsD.Bounds[2] + " " + gpsD.Bounds[3]);
                lb.Items.Add("Waypoint");
                foreach (WayPoint wp in gpsD.DataList)
                {
                    lb.Items.Add(wp.Name + " " + wp.Latitude + " " + wp.Longitude + " " + wp.Ele + " " + wp.Sym);
                }
                tabPage.Controls.Add(lb);
                pn++;
                tabPage.Padding = new System.Windows.Forms.Padding(3);
                tabPage.Size = new System.Drawing.Size(192, 74);
                tabPage.TabIndex = 0;
                tabPage.Text = name;
                tabPage.UseVisualStyleBackColor = true;
                tabs.Add(tabPage);
                tabControl1.Controls.Add(tabPage);
                tabPage = new TabPage();
                tabPage.Location = new System.Drawing.Point(4, 22);
                tabPage.Name = "tabPage" + pn;
                pn++;
                tabPage.Padding = new System.Windows.Forms.Padding(3);
                tabPage.Size = new System.Drawing.Size(192, 74);
                tabPage.TabIndex = 0;
                tabPage.Text = mapName;
                string location = path + mapName;
                tabPage.UseVisualStyleBackColor = true;
                tabs.Add(tabPage);
                PictureBox pb = new PictureBox();
                pb.Name = "pictureBox" + pn;
                pb.Image = Image.FromFile(location);
                tabControl2.Controls.Add(tabPage);
                pb.Width = pb.Image.Width;
                pb.Height = pb.Image.Height;
                tabPage.Controls.Add(pb);
                currentComponent = tabPage;
                tabPage.Width = pb.Width;
                tabPage.Height = pb.Height;
                pn++;
                tabControl2.Width = pb.Width;
                tabControl2.Height = pb.Height;
                bmp1 = (Bitmap)pb.Image;
                int lx, ly;
                float realWidth = gpsD.Bounds[1] - gpsD.Bounds[3];
                float imageW = pb.Image.Width;
                float dx = imageW * (gpsD.Bounds[1] - gpsD.getWayPoint(0).Longitude) / realWidth;
                float realHeight = gpsD.Bounds[0] - gpsD.Bounds[2];
                float imageH = pb.Image.Height;
                float dy = imageH * (gpsD.Bounds[0] - gpsD.getWayPoint(0).Latitude) / realHeight;
                lx = (int)dx;
                ly = (int)dy;

                using (Graphics g = Graphics.FromImage(bmp1))
                {
                    Rectangle rect = new Rectangle(lx, ly, 20, 20);
                    if (gpsD.getWayPoint(0).Sym.Equals(""))
                    {
                        g.DrawRectangle(new Pen(Color.Red), rect);
                    }
                    else
                    {
                        if (gpsD.getWayPoint(0).Sym.Equals("hospital"))
                        {
                            g.DrawImage(symbolImages[0], rect);
                        }
                        else
                        {
                            if (gpsD.getWayPoint(0).Sym.Equals("university"))
                            {
                                g.DrawImage(symbolImages[1], rect);
                            }
                        }
                    }
                }
                pb.Image = bmp1;
                pb.Invalidate();

            }

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void addBtn_Click(object sender, EventArgs e)
        {

            string wayName = nameTxtBox.Text;

            double lat = Convert.ToDouble( latTxtBox.Text);
            float wayLat = (float)lat;


            double lon = Convert.ToDouble( longTxtBox.Text);
            float wayLong = (float)lon;


            double ele = Convert.ToDouble(elevTxtBox.Text);
            float wayEle = (float)ele;

            WayPoint wp = new WayPoint(wayName, wayLat, wayLong, wayEle);

            GPSDataPoint.Add(wp);
         }




        private void lb_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            MessageBox.Show(lb.SelectedIndex.ToString());
        }
    }
}

GPSDataPoint.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CourseworkExample
{
    public class GPSDataPoint
    {
        private float[] bounds;
        private List<WayPoint> dataList;
        public GPSDataPoint()
        {
            dataList = new List<WayPoint>();
        }
        internal void setBounds(string p)
        {
            string[] b = p.Split(',');
            bounds = new float[b.Length];
            for (int i = 0; i < b.Length; i++)
            {
                bounds[i] = Convert.ToSingle(b[i]);
            }
        }
        public float[] Bounds { get { return bounds; } }
        internal void addWaypoint(string s)
        {
            WayPoint wp = new WayPoint(s);
            dataList.Add(wp);
        }
        public WayPoint getWayPoint(int i)
        {
            if (i < dataList.Count)
            {
                return dataList[i];
            }
            else
                return null;
        }
        public List<WayPoint> DataList { get { return dataList; } }

        internal void Add(WayPoint wp)
        {
          //  dataList.Add(wp);
        }
    }
}

WayPoint.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CourseworkExample
{
    public class WayPoint
    {
        private string name;
        private float ele;
        private float latitude;
        private float longitude;
        private string sym;


        public WayPoint(string name, float latitude, float longitude, float elevation)
        {
            this.name = name;
            this.latitude = latitude;
            this.longitude = longitude;
            this.ele = elevation;
        }

        public WayPoint()
        {
            name = "no name";
            ele = 3.5F;
            latitude = 3.5F;
            longitude = 0.0F;
            sym = "no symbol";

        }

        public WayPoint(string s)
        {
            string[] bits = s.Split(',');
            name = bits[0];
            longitude = Convert.ToSingle(bits[2]);
            latitude = Convert.ToSingle(bits[1]);
            if (bits.Length > 4)
                sym = bits[4];
            else
                sym = "";
            try
            {
                ele = Convert.ToSingle(bits[3]);
            }
            catch (Exception e)
            {
                ele = 0.0f;
            }
        }

        public float Longitude
        {
            get { return longitude; }

            set { longitude = value; }
        }

        public float Latitude 
        {
            get { return latitude; }
            set { latitude = value; }

        }

        public float Ele 
        {   
            get { return ele; }
            set { ele = value; }
        }
        public string Name 
        {

            get { return name; }
            set { name = value; }

        }

        public string Sym
        {   
            get { return sym; }
            set { sym = value; }        
        }
    }
}

Besides, .csv file looks like

birthplace.png
51.483788,-0.351906,51.460745,-0.302982
Born Here,51.473805,-0.32532,-,hospital
Born Here,51.473805,-0.32532,-,hospital

I am getting an error whenever I want to use GPSDataPoint.Add(wp); I must be doing very silly mistakes but I cant see it. Please help me. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:54:46+00:00Added an answer on June 15, 2026 at 9:54 pm

    You need to change the following function:

    private void addBtn_Click(object sender, EventArgs e)
        {
    
            string wayName = nameTxtBox.Text;
    
            double lat = Convert.ToDouble( latTxtBox.Text);
            float wayLat = (float)lat;
    
    
            double lon = Convert.ToDouble( longTxtBox.Text);
            float wayLong = (float)lon;
    
    
            double ele = Convert.ToDouble(elevTxtBox.Text);
            float wayEle = (float)ele;
    
            WayPoint wp = new WayPoint(wayName, wayLat, wayLong, wayEle);
    
            GPSDataPoint gdp = new GPSDataPoint();
            gdp.Add(wp);
    
            //Do something with your gdp variable or use the public on you have declared instead
            //gpsdp.Add(wp);
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to work on a project which involves running/executing the java file
Hello I am trying to display work orders from my mysql database to show
I'm trying to work this out. In my project, i have a file called
I'm trying to make work this example from http://developer.android.com/resources/tutorials/views/hello-timepicker.html , no errors while compiling
Hello everyone I'm trying to work with jboss messaging, does anyone knows the default
hello i am trying to load a list of filenames from a folder into
Hello I was trying to remove objects from object array that I have and
Hello everyone I am trying to get an audio tag to work in rails.
I'm trying to set up a basic hello world project using Eclipse Indigo and
I'm trying to make a simple application similar to the commonly used Hello World

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.