DatagridView import Coordinates C#

DatagridView import Coordinates C#

k005
Advisor Advisor
2,103 Views
8 Replies
Message 1 of 9

DatagridView import Coordinates C#

k005
Advisor
Advisor

 

 

Hello

 

How can I import the attached file from DatagridView?

 

Thanks

0 Likes
Accepted solutions (1)
2,104 Views
8 Replies
Replies (8)
Message 2 of 9

Liesl_H
Advocate
Advocate

You need to convert the .txt file to a .csv file first of all, then (if you are using Civil 3D) in the insert tab, in the import tab, "points from file". These points have no additional data like elevation or ID so you could not make a surface or assign names to the points. What are you trying to accomplish with this data? 

0 Likes
Message 3 of 9

k005
Advisor
Advisor

@Liesl_H 

 

I want to take this data from the txt file and draw Dwg. these only have Point coordinates. Yes. There is no height.

My goal: to create the drawing with these x and y values. then Area account etc.

0 Likes
Message 4 of 9

Liesl_H
Advocate
Advocate

OK then import the points as a .csv file as I described - if it is just the points you are after I don't think you need to worry about the style; default styles will be fine. After points are imported, zoom extents (maybe have to change pdmode to something other than 0 to see them better) and then you will have to connect the dots to create a polygon. Select polygon to calculate volume. 

 

I made the file into csv for you (attached). When you import, remember your file is PENZD (Point #, Easting, Northing, no Z and no D so they are zero.) If your northing was in column 2 it would be PNEZD. (I am assuming your northings are the third column.)

0 Likes
Message 5 of 9

k005
Advisor
Advisor
Accepted solution

@Liesl_H 

 

Thank you for the csv file. But first of all, we will take the data in the .txt file that I have sent, as a datagrid.

 

I will draw it in the next step. This will be a plus feature in the Plug-in file I have prepared.

 

Do you have experience with C #?

0 Likes
Message 6 of 9

norman.yuan
Mentor
Mentor

Your question is more of generic .NET UI programming basics (assume you use Win Form). It is 2-step tasks: reading data into a collection of IEnumerable<T>/ICollection<T>, so that it can be used to bind to DataGrid (note, if you do use WInForm, do not use older DataGrid control, instead, use DataGridView control); once you have data read from text file (or whatever file format), you can simply bind it to the DataGridView by setting its DataSource property to your data collection object.

 

This forum is not a good place to ask/learn this type of topic, IMO.

 

To read data from file, you look into System.IO for StreamReader/TextReader class. for simple Text file, you can simply call File.ReadAllLines()/ReadAllText() and then you organizee the data into an object collection.

 

 As for DataGridView, if you google "WinForm DataGridView", you would get thousands, if not million, of links, many of them are tutorials with code samples. YouTube would also has tons of shows on how to use DataGridView.

 

HTH

 

Norman Yuan

Drive CAD With Code

EESignature

Message 7 of 9

k005
Advisor
Advisor

@norman.yuan 

 

I have solved the issue as of the moment. 🤗

 

 

 

So how can I draw the data from datagridview into dwg file as polyline?

0 Likes
Message 8 of 9

fsztuczny
Advocate
Advocate

Don't expect someone to do the work for you. You have to try to find a solution yourself. If you have a problem, try to fix it. If you can't, then ask. I also started a dozen or so years ago. The results will come over time if you keep working on yourself. My hint is that you need to add a reference to System.Windows.Forms and optionally System.Drawings. Start with this:

 

https://www.aspsnippets.com/Articles/Populate-Bind-DataGridView-without-using-Database-in-Windows-Fo...

https://www.guru99.com/c-sharp-stream.html#1

https://www.completecsharptutorial.com/csharp-articles/csharp-string-function.php

https://through-the-interface.typepad.com/through_the_interface/2007/06/using-a-modal-1.html

Message 9 of 9

k005
Advisor
Advisor

@fsztuczny 

 

 

Yes, I do exactly that. I don't wait

0 Likes