Hi All,
first of all thanks for the time you are putting in reading this.
i need assistance in the following.
i have a datagridview in which is being filled from a database.
what i want to do is the following:
check a specific cell in a row and compare it to the previous one. in case they are the same do one thing, in case they are different do another one.
for example:
the datagridview has a column name, long, lat.
Row Name Long Lat
1 AZ1 55.555522 55.555522
2 AZ1 55.555533 55.555533
3 AZ1 55.555544 55.555544
4 AZ1 55.555555 55.555555
5 AZ2 55.555522 55.555522
6 AZ2 55.555533 55.555533
7 AZ2 55.555544 55.555544
8 AZ2 55.555555 55.555555
and so on.
what i want to do the following:
if row[2].cell[name] = row[1].cell[name]
{
do XXXXXXXXXXXXXXXXX
}
else
{
do yyyyyyyyyyyyyyyyyyyyy
}
hope i am clear.
once again.
thanks
Loading
j kPosted Sep 20, 2013, 3:06 PM
the purpose of this application is to eventually create an KML (google earth) file with specific coordinates take from the sql server.
as i mentioned above the query i created eventually will give me this
Row Name Long Lat
1 AZ1 55.555522 55.555522
2 AZ1 55.555533 55.555533
3 AZ1 55.555544 55.555544
4 AZ1 55.555555 55.555555
5 AZ2 55.555522 55.555522
6 AZ2 55.555533 55.555533
7 AZ2 55.555544 55.555544
8 AZ2 55.555555 55.555555
i want the application to create a kml file for each name with the relevant coordinates.
the kml file should look like this
55.555522, 55.555522,0 55.555533, 55.555533,0 55.555544 55.555544,0 55.555555, 55.555555,0
i can not do it via the database.
thanks
Suthish NairPosted Sep 17, 2013, 6:11 AM
j kPosted Sep 15, 2013, 2:51 PM
sorry for the long long reply, i didnt have time to continue working on this.
[code]
class LatLongPair
{
public double Lat { get; set; }
public double Lon { get; set; }
} private void button4_Click(object sender, EventArgs e)
{
Dictionary
List
LatLongPair lPair = null;
string matchHandle = string.Empty;
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
if (dataGridView2.Rows[i].Cells[0].Value.ToString() == matchHandle)
{
lPair.Lat = Convert.ToDouble(dataGridView2.Rows[i].Cells[1].Value);
lPair.Lon = Convert.ToDouble(dataGridView2.Rows[i].Cells[2].Value);
lst.Add(lPair);
}
else
{
matchHandle = dataGridView2.Rows[i].Cells[0].Value.ToString();
lPair = new LatLongPair();
lPair.Lat = Convert.ToDouble(dataGridView2.Rows[i].Cells[1].Value);
lPair.Lon = Convert.ToDouble(dataGridView2.Rows[i].Cells[2].Value);
lst = new List
lst.Add(lPair);
LatLongCollectionByName.Add(matchHandle, lst);
}
}
foreach (KeyValuePair
{
Console.WriteLine("\n For name : "+ item.Key + ", lat/long vaues are:\n" );
foreach (LatLongPair lp in item.Value)
{
Console.Write("\t"+ lp.Lat + ",\t" + lp.Lon +" | ");
}
}
}
[/code]
i have added the below code and i get the following error
LatLongCollectionByName.Add(matchHandle, lst);
"An item with the same key has already been added."
any idea what i am doing wrong.
thanks
Hemant SrivastavaPosted Jun 24, 2013, 6:06 PM
It looks like, you need to keep on collecting all the Lat, Long pairs for a name (say AZ1) from the DataGrid until you get another different name (say AZ2)
If this is the case, then you may try following:
class LatLongPair
{
public double Lat { get; set; }
public double Lon { get; set; }
}
private void button4_Click(object sender, EventArgs e)> LatLongCollectionByName = new Dictionary>();
{
Dictionary
List lst = null;
LatLongPair lPair = null;
string matchHandle = string.Empty;
for (int i = 0; i < dataGridView2.Rows.Count; i++)
{
if (dataGridView2.Rows[i].Cells[0].Value.ToString() == matchHandle)
{
lPair.Lat = Convert.ToDouble(dataGridView2.Rows[i].Cells[1].Value);
lPair.Lon = Convert.ToDouble(dataGridView2.Rows[i].Cells[2].Value);
lst.Add(lPair);
}
else
{
matchHandle = dataGridView2.Rows[i].Cells[0].Value.ToString();
lPair = new LatLongPair();
lPair.Lat = Convert.ToDouble(dataGridView2.Rows[i].Cells[1].Value);
lPair.Lon = Convert.ToDouble(dataGridView2.Rows[i].Cells[2].Value);
lst = new List();
lst.Add(lPair);
LatLongCollectionByName.Add(matchHandle, lst);
}
}
foreach (KeyValuePair> item in LatLongCollectionByName)
{
Console.WriteLine("\n For name : "+ item.Key + ", lat/long vaues are:\n" );
foreach (LatLongPair lp in item.Value)
{
Console.Write("\t"+ lp.Lat + ",\t" + lp.Lon +" | ");
}
}
}
j kPosted Jun 23, 2013, 5:14 PM
thanks for the prompt reply.
the google file is not related to the problem or to the request as i know how to do it.
the solution you gave me is great but i believe i might have explained my request wrong.
as i stated in my previous thread is what i need.
your help is much appriciated.
in case you still think that i need to close this thread and open a new one i will be more than glad.
thanks
Hemant SrivastavaPosted Jun 23, 2013, 5:03 PM
If you problem in this thread is resolved, please close it by marking it accepted answer and ask your another question (i.e. creating a kml (google) file ) in a new seperate thread so that everybody could easily identify your problem by the title and resolve your problem.
Thanks
j kPosted Jun 23, 2013, 7:54 AM
i need another solution.
what i am trying to do is to create a kml (google) file. i have all the correct structure and i know how to create a placemark. what i need now is to create a polygon.
the golygon structure is as following:
[code]
-99.45696372596203,37.32189377103684,0 -99.49736053699029,37.27114252929838,0 -99.5340836799392,37.1844040891404,0 -99.54670936783666,37.15948456478002,0 -99.5046176338825,37.04142373560555,0 -99.43502416220858,36.94915619082043,0 -99.4129089660931,36.87807736321675,0 -99.40935748409949,36.84207292215385,0 -99.35734612071829,36.77279523264249,0 -99.21562481188708,36.70886314083075,0 -99.04416248174212,36.64648190158864,0 -98.89339195357744,36.6430665697914,0 -98.69875389788192,36.65396902583192,0 -98.56605650583366,36.68537699809853,0 -98.46532722103743,36.73910787529999,0 -98.3564795792729,36.87757329711507,0 -98.36684582292646,36.99780464926464,0 -98.44604199551019,37.21100605772616,0 -98.92853300559456,37.51010527366783,0 -99.45696372596203,37.32189377103684,0
[/code]
since my kml file is getting the data from a datagrid view and contains the below data:
[code]
Row Name Long Lat
1 AZ1 55.555522 55.555522
2 AZ1 55.555533 55.555533
3 AZ1 55.555544 55.555544
4 AZ1 55.555555 55.555555
5 AZ2 55.555522 55.555522
6 AZ2 55.555533 55.555533
7 AZ2 55.555544 55.555544
8 AZ2 55.555555 55.555555
[/code]
what i need is eventruall that for each "name" if will add just the points. for example
[code]
55.555522, 55.555522,0 55.555533, 55.555533,0 55.555544 55.555544,0 55.555555, 55.555555,0
[/code]
thanks
Hemant SrivastavaPosted Jun 19, 2013, 1:46 PM
Hemant SrivastavaPosted Jun 19, 2013, 1:45 PM
for(int i=1;i< dataGridView1.Rows.Count;i++)
{
if (dataGridView1.Rows[i].Cells[0].Value.ToString() == dataGridView1.Rows[i-1].Cells[0].Value.ToString())
{
// DO XXXXXXXXXXX
}
else
{
// DO YYYYYYYYYY
}
}