Write to CSV with button. Used for Bartender

Ok I’ve figured it out. You have to deploy your dashboard as an assembly, Add it to you menu, then you can customize it proper.

The only catches I saw was that I had to access the button you created as a system control (using csm.GetaNativeControlReference) which means you can NOT use the wizard to create the onClick event.

I’ve done that manually.Once you deploy your DB as assembly and open customization, you can use this as a guide. NOTE your GUID’s are probably going to be different for your grid and button but you can get those from the properties tab.

// Created: 3/20/2017 9:31:22 AM
// **************************************************
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Ice.BO;
using Ice.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;

public class Script
{
	// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module Level Variables' Comments! **
	// Begin Wizard Added Module Level Variables **

	// End Wizard Added Module Level Variables **

	// Add Custom Module Level Variables Here **
EpiUltraGrid LabelGrid;
EpiButton PrintButton;
string datas;
string headers;
string myCSV;

	public void InitializeCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Variable Initialization' lines **
		// Begin Wizard Added Variable Initialization

		// End Wizard Added Variable Initialization

		// Begin Wizard Added Custom Method Calls

		// End Wizard Added Custom Method Calls

 		LabelGrid = (EpiUltraGrid)csm.GetNativeControlReference("8d6c1c8e-c9b5-46f6-b859-4895c6c990ea");
		 PrintButton = (EpiButton)csm.GetNativeControlReference("312c5ff2-89c0-48ac-94ec-b2ec1dfdbf36");

			PrintButton.Click += new EventHandler(PrintClick);
	}

	public void DestroyCustomCode()
	{
		// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Object Disposal' lines **
		// Begin Wizard Added Object Disposal

		// End Wizard Added Object Disposal

		// Begin Custom Code Disposal

		// End Custom Code Disposal
			PrintButton.Click -= new EventHandler(PrintClick);
	}

    private void MakeLabelData(string pn, string desc)
	{
		this.headers = string.Format("\"{0}\",\"{1}\"", new object[]
		{
			"pn",
			"desc"
		});
        this.datas = string.Format("\"{0}\",\"{1}\"", new object[]
		{
			pn,
			desc
		});
	}

	private void PrintClick(object sender, EventArgs e)
	{
		string to = "\\\\Server\\Folder\\junk.txt";
                string[] source = {""};


		myCSV = ""; //make sure our CSV is empty
		foreach(var row in LabelGrid.Rows)   //.the var row now represents the current row as we iterate
		{
		   if(row.Selected)// for only selected rows
		   {
		    addDataToCSV(row.Cells["Part_PartNum"].Value.ToString());                          
		    addDataToCSV(row.Cells["Part_PartDescription"].Value.ToString());                          
		    
		
		   }
		}
	
		MessageBox.Show("CSV: " + myCSV);
		source[0] = myCSV;
		System.IO.File.WriteAllLines(to,source);
        
	}

		private void addDataToCSV(string datastring)
        {
            if (myCSV.Length > 0) myCSV += ",";
            myCSV += "\"" + datastring + "\"";
        }

}
2 Likes