Copy to clipboard from grid in code

I want to set up a dashboard for my users in shipping that allows them to select rows in a grid, then with a button, copies the correct data, in the correct format to be able to paste insert into the subcontractor shipping entry list screen.

It looks like I should be able to copy to the clipboard using the code.

Clipboard.SetText("MyInfo");

found here.

For formatting, it looks like it’s just tab delimited fields. So theoretically I should be able to loop through the grid for selected, build up the string, using /t for the tabs, then copy it to the clipboard in the correct format right?

The reason I want to do this instead of just copying the grid is because there are reference columns that will be necessary in the source grid that cannot be in the target grid. So instead of trying to get my users to be able to correctly format the rows in Excel (I have a technologically illiterate group here), it would be easier to just select and copy.

Has anyone done this before? Does that plan sound logical?

I have a second question as well, which is, are there any tricks to help be sure that the data is 100% current at the time of the copy button? I’m thinking it would have to be run the same query with a DynamicQuery adapter and compare results, then if they didn’t match stop the copy? That sounds like a lot of coding, but I don’t know of a simpler way. Any ideas?

Also, another random thought, maybe it would be better to create a search for lines on the subcontract shipment entry? Currently the search only allows for single selection at a time. We need multiple selection.

Isn’t there an Enivornment.Tab? :wink:

Or does the the “magic string” of "\t" have to be used?

If the interwebs are to be believed…

And now the most annoying thing about that, if the /t is standardized across platforms, why isn’t /r/n??

1 Like

I use Notepad2 as my default text editor. So it looks like we can blame the Unix folks, Steve Jobs, and Bill Gates.

And since when is the TAB the universal record separator?

I’ve exported from E10, and found RS chars (code 0x1E) as a record separator.

I don’t know if it is or isn’t, that just what I’m seeing when I copy past from a grid into NotePad ++

Every time that character comes up for me it’s because it’s derping something up and I have to find and remove them.

What 0x1E seems to do to my system.

2 Likes

M E T A
E
T
A

Same for me.
I ended up paying someone on fiverr.com to write me a script to scrub the database of the character. It’s been working well.

My least favorite characters are:

  1. RS (0x1e)
  2. (that’s a “long” dash, code 150d or 0x96)
  3. and - the fancy quotes.
  4. (that’s a wide space, code 160d or 0xA))

Those last three make their way in when copying and pasting for other sources - especially web sites.

Looks like you’re spot on with your code. I just tested this out and it seems to work the way you describe:

    EpiUltraGrid eugOD = (EpiUltraGrid)csm.GetNativeControlReference("bec51417-b286-4d61-a471-3912bc098905");

	string strBuilder = "";

	foreach(UltraGridRow r in eugOD.Selected.Rows)
	{
		strBuilder += r.Cells["OrderLine"].Text.ToString() + "\t" + r.Cells["PartNum"].Text.ToString() + "\t" + r.Cells["LineDesc"].Text.ToString() + Environment.NewLine;
	}
  
    Clipboard.SetText(strBuilder);
1 Like

Well thanks! I was going to figure out the code myself, but you just made my job easier.

1 Like

You can do the dynamic query part. :stuck_out_tongue:

I think I might skip that for now and just :crossed_fingers:

Relying on a little training should hopefully not screw us up.

Well–the stale data isn’t going to be any different if you didn’t have a copy button and they just copied from the grid the standard way. Are you copying from a dashboard, or something, where the data would be more live versus in order entry or something?

Correct,

Basically, we have very large BOM’s for our jobs. Each job is a whole conveyor, with the structure matching the CAD model. (no MRP, job to job, or job to inventory for the most part). So if we have a conveyor that has parts that need to get sent out for subcontract work (like galvanizing) not only are there a lot of unique part numbers, there are a lot of assembly sequences for likely the same part number. So for subcon work, I want to get them to start using the SubContract Shipment Entry screen so we at least have some record that it left the building, as well as some visibility to what’s coming up in the schedule, both on the shipping and receiving side. Up to this point, the just didn’t do that, there was no record as far as I could tell on what got sent out, and when it was supposed to come back.

All that to say, a single shipment entry might end up being 20 or 30 or more lines, so manually entering them sucks. So I created a BAQ and Dashboard to basically duplicate the Subcontract Status report, and I want to be able to paste insert those lines into the subcon shipment entry.

I’ve got the BAQ and Dahsboard and am just starting the customization for the button now so they don’t have to copy paste into excel, reformat, back to E-10.

Gotcha.
Aside from having them refresh before they copy, then you’d probably be good with calling the query in code and using that data. The difficulty would be if they’re only selected a few lines instead of all of them. If they did that, you would need to find a way to compare what they have selected against the data the query returns and build off of that.

I had to change

to

foreach(var r in eugOD.Selected.Rows)

But otherwise that seems to work beautifully!

1 Like

Now make it find which columns are visible, and add them in the order they’re displayed. :wink:

That’s called “right click, copy” I didn’t want it that way, which is why I went this direction.

Hey Brandon, Is directly inserting the rows from the BAQ into a pack not an option? It just seems easier than having the user click the copy button and then go to the pack to paste it.

It’s possible, but I guess I didn’t want to tackle trying to handle whether it’s a new pack, or updating an existing one. Depending on what’s being sent, it still might be sections of the list at a time on one pack, so I don’t want to create one every time they click the button, and they have to print it anyways, so I figured that would be in the screen since I don’t want to recreate the whole thing. It seemed simpler this way.

But if you think you have a more intuitive flow, I’m all for stepping through it.