|
-
Mar 17th, 2021, 04:33 PM
#1
Thread Starter
Lively Member
How to paste data into multiple cellls in datagridview
Hi, i'm trying to copy datas like the following

So I'm copying
03-17 10:55:03 DOGE/EUR Limit Buy 0.04816 0.04816 11,740.0 11,740.8 565.39840
(eventhough I don't know why when I copy it on a notepad or also here, it just doesn't stay in line like in the screenshot, but the values are being pasted one under the other...) .The datagrid columns are so 9 (Date, Pair, Type etc) When I'm going to paste it into the first column of datagridview, it doesn't paste also in the others, but just the first column date cell is filled with "03-17 10:55:03".
Is there a possibility to paste the values splitted respectively into their columns?
Thanks
-
Mar 17th, 2021, 06:17 PM
#2
Re: How to paste data into multiple cellls in datagridview
Where (what application and or form tool) are you copying the data from?
If you are getting the data with each field on a new line, then the copy operation is copying additional characters or formatting that is adding the newline characters.
-
Mar 18th, 2021, 03:25 AM
#3
Thread Starter
Lively Member
Re: How to paste data into multiple cellls in datagridview
Hi, i m copying that from my open orders in Binance, a website. As you can see between values there is a space, it might be that.
P.s. im gettjne each field in new line when i m pastinf on notepad. Obviously in datagridview nothing is being pasted if not just the date, and i m trying to fogure it out how to paste each field in their relatives columns
-
Mar 18th, 2021, 08:07 AM
#4
Re: How to paste data into multiple cellls in datagridview
I *think* you'll need to handle it yourself...in the cell key down or something like that, check for the paste command, get the data from the clipboard, see if there are newlines, parse the data, then start inserting the data into the appropriate cells.
-tg
-
Mar 18th, 2021, 08:50 AM
#5
Thread Starter
Lively Member
Re: How to paste data into multiple cellls in datagridview
Would you be able if you dont mind to provide me some documentations ? It would be helpful to me. Thanks
-
Mar 18th, 2021, 11:38 AM
#6
Re: How to paste data into multiple cellls in datagridview
It may not be as helpful as you are hoping for.
You have one great advantage working for you: That Binance site!!
What that does for you is means that you can probably count on the data staying roughly the same, but you'll have to do some studying to figure out what it is. I've done something a bit like this with importing files that were mostly supposed to be CSV files. In my case, the key turned out to be that "mostly" word. People found all kinds of weird ways to come up with CSV files that would technically be CSV files, but would differ in a variety of ways. It took a fair amount of time before my code handled all the strange little variants that people were coming up with. You get to avoid all that, because you will likely be able to count on the files being just one type, with one format, and rarely changing once set. Still, you need to find that format as a first step. The rest is relatively easy, but will change depending on that format.
What I'd do to start is to paste the data into Notepad. Notepad is a pretty simplistic program that does pretty much NOTHING for you. No formatting, no interpretation, nothing. You just splat the data in there, and it shows you whatever it is. What I like about that is that, if there are separators, you will tend to see them. If there are newline characters, you'll get multiple lines (that's about the only formatting that Notepad does). Just knowing whether you have newline characters is useful. If you do, then you know that you can look for those to figure out when to go to a new row. If you don't have them, then you'll have to look at the data more closely to figure out how to separate them into different rows. There might be some other character, aside form the newline, which works for this, or it might be something worse, but at least you'll be able to see. You can also see what characters are used to separate fields, which is usually a comma, but that could be language dependent.
So, the first step is to look at the data to be sure that you can say, "this tells me to start a new row", and also "this tells me to start a new field". If you can do that, you're more than halfway, because you have enough to fill a datatable, and since you can bind a datatable to a DGV, that might be all you really want to do. You'd create your own datatable, add the fields that you will need, then you can call dt.NewRow to get a new datarow (one for each row, so you need to know when the rows break), then you can write something like
yourRow("yourField") = someValue
to put the value into the field (one for each field, so you'd need to know where the fields break). So, that part is relatively easy, once you have taken a good look at the structure of the data.
My usual boring signature: Nothing
 
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|