Copy to clipboard from grid in code

I recently had a request similar to this.

Mine was based in project entry and they wanted a fast way to attach quotes. I made a BAQ view within project entry of available quote lines, made a filtering field similar to a dashboard, the user could select multiple rows, even from different quotes and click a Add. This would run through the recselected and using an adapter attach the selected, then refresh the baq view to remove the used quote lines as well as the project to show the newly attached quotes.

So my suggestion, if you feel like doing it, would be to build this into the shipping form and it’s up to the user to make a new pack or use an existing one and your script would use what ever is on screen.

I can shoot you examples if you need assistance.

1 Like

Thanks Dan, That would be good to learn. I haven’t done a BAQ view before, so some example code on that would be very much appreciated.

So basically, I could have the BAQ view, and end up with basically one way list picker if if I handled the refreshing the right way (So it refreshes after the lines are added)? Then, as long and I have the filters set correctly, they shouldn’t be able to add anything erroneously?

First you’ll want to reference the Dynamic Query Adapter.
Create your grid.
Initialize your script in InitializeCustomCode using ā€œLoadProjects();ā€ for this example.

Modify this script that I made comments on:

private void LoadProjects() {
DynamicQueryAdapter baqAdapter = new DynamicQueryAdapter(oTrans); //Call Adapter
baqAdapter.BOConnect();
baqAdapter.ExecuteByID(ā€œScheduleProjectsā€); //BAQ NAME

  EpiDataView edvProjects = new EpiDataView();
  edvProjects.dataView = new DataView(baqAdapter.QueryResults.Tables["Results"]); //Add Results to EpiDataView

  foreach(DataColumn dc in edvProjects.dataView.Table.Columns) { //Make read only
  	dc.ExtendedProperties["ReadOnly"] = true;
  	dc.ExtendedProperties["Like"] = dc.ColumnName.ToString(); //Column Names
  }
  if((oTrans.EpiDataViews.ContainsKey("ProjectsView") == false)) {
  	oTrans.Add("ProjectsView", edvProjects); //Add view
  }
  baqAdapter.Dispose();

}

and then save/close, reload the form and bind the grid to the ā€œProjectsViewā€ in the EpiBinding property of the grid.

1 Like

Hey Brandon,

I didn’t like my answer to you earlier. I’ve been trying to figure out a quick/easy way to bind a grid and refresh it for my own projects. I think I’ve figured out a low cost way and wanted to update what I told you earlier.

Add Reference DynamicQueryAdapter.

Then use the script:

private void LoadProjects() {

  DynamicQueryAdapter baqAdapter = new DynamicQueryAdapter(oTrans);
  baqAdapter.BOConnect();
  baqAdapter.ExecuteByID("ScheduleProjects"); //BAQ Name
  grdProjectSelect.DataSource = baqAdapter.QueryResults.Tables["Results"]; //Load DataTable to grid using just grid name.(dont bind using properties)
  baqAdapter.Dispose(); 	}

drop ā€œLoadProjects();ā€ into your initialize script.
Call LoadProjects(); when ever you need to refresh.

1 Like

ok, That’s basically what I have going on. I’ve been using this video again to get the BAQ into the grid. I’m pretty sure it’s basically what you have there, you just don’t have any parameters.

So I end up with this, which I put into a View Notification event. Whenever you load in a supplier, the lines for that supplier show up in the line picker grid.

private void edvSubShipH_EpiViewNotification(EpiDataView view, EpiNotifyArgs args)
{
	// ** Argument Properties and Uses **
	// view.dataView[args.Row]["FieldName"]
	// args.Row, args.Column, args.Sender, args.NotifyType
	// NotifyType.Initialize, NotifyType.AddRow, NotifyType.DeleteRow, NotifyType.InitLastView, NotifyType.InitAndResetTreeNodes
	if ((args.NotifyType == EpiTransaction.NotifyType.Initialize))
	{
		if ((args.Row > -1))
		{
		DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
		dqa.BOConnect();
		QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("SubConShipPaste");
		qeds.ExecutionParameter.Clear();
		qeds.ExecutionParameter.AddExecutionParameterRow("VendID", view.dataView[args.Row]["VendorNum"].ToString() , "nvarchar" , false , Guid.NewGuid(),"A");
		dqa.ExecuteByID("SubConShipPaste",qeds);
		subsGrid.DataSource = dqa.QueryResults.Tables["Results"];
		}
	}
}

The problem that I am having now, is I have stuff in the BAQ that I need for filtering purposes, but I don’t want to show up in the grid for the end user. Since the grid is populated dynamically, I don’t have any control over it.

So I think I might have to look at your first answer because I need an established data view in order to control the grid the way I need. (I think???)

Another thought is the bury the current top level with the required information in a subquery and only show the fields I want visible in the top level. That could probably work ok.

You can actually control the grid columns themselves after the fact.

UltraGridColumn column1 = grdProjectSearch.DisplayLayout.Bands[0].Columns[ā€œColumn_Nameā€];
column1.Header.Hidden = true.

that might not be 100% but close.

1 Like

I’ll see what I can do. I wonder if I can use named columns?

Do the display fields need to be visible to filter on within a BAQ?

They are calculated, so yeah… You can filter on the table without them being visible, but I have some calculated fields that determines whether that line should be available for them to pick or not. For that I use the SubQuery Criteria.

I create a .csv from the selected rows in a grid. The user selects the rows that they want to copy, press a button which runs the code that uses streamwriter to create the .csv file. In the code I decide what fields are sent to the .csv and in what order. and where the file is saved to. This same code can be used to copy it to the clipboard only. That code is at the bottom and its commented out.

using System.IO;
using System.Collections;
using System.Collections.Generic;
using Infragistics.Win.UltraWinGrid;

private void epiButtonC1_Click(object sender, System.EventArgs args)
{
Infragistics.Win.UltraWinGrid.SelectedRowsCollection selectedRows;
using (StreamWriter lf = new StreamWriter(@ā€œ\C\hold\VLM.csvā€, false)) //csv file name and location

	{
		EpiUltraGrid eugMySelections = (EpiUltraGrid)csm.GetNativeControlReference("b631eaf6-a370-4858-b1f6-92854038dd4c");  //GUID of the grid
      		  	            
        selectedRows = eugMySelections.Selected.Rows;

		if ( selectedRows.Count < -1 ) // Get the selected rows.
        		return;

        	System.Text.StringBuilder sb = new System.Text.StringBuilder( );//builds string for clipboard
			for ( int i = 0; i < selectedRows.Count; i++ )
        	{
        		Infragistics.Win.UltraWinGrid.UltraGridRow row;
        
        		row = selectedRows[i];
				//the following sends it to the csv file


				lf.Write(row.Cells[ "OrderNum" ].Text );
				lf.Write(",");


        		lf.Write( row.Cells["OrderLine"].Text );
				lf.Write(",");

				lf.Write( row.Cells[ "ShortChar06" ].Text );  // EDP
				lf.Write(",");

				lf.Write( row.Cells["Quantity"].Text );
				lf.Write(",");
        		
				lf.Write(row.Cells[ "FromBinNum" ].Text );
				lf.Write(",");

        		lf.Write( row.Cells["OrderLine"].Text );
				lf.Write(",");


				
				lf.Write("\""); // this send message that this is the end of the order
				lf.Write("\r\n"); //this send a line break/return

				//sb.Append( row.Cells[ "PartNum" ].Text ); //this sends it to the clipboard
				//sb.Append( "," );
        		//sb.Append( "\r\n" );//this appends to the end of the clipboard the next line from the grid
			
	
        	}
				MessageBox.Show("Exported");

        		//System.Windows.Forms.Clipboard.SetDataObject( sb.ToString( ) );// Copy the text to the clipboard.

	}
}
1 Like