Just an update, Justin_Chilton, while your solutions works, it was extremely slow for very large tables (and turned out to be inadequate for my needs)
It is much faster to use
JmpDT.GetColumn(ColName).SetDataVector (which populates 1 column at a time)
instead of
jmpDT.GetColumn(col.ColumnName).SetCellVal
Which only populates 1 cell at a time
So you just need code to convert data columns in datatables into array to feed into the SetDataVector method
example: string[] ColArray = Summary.AsEnumerable().Select(rw => rw.Field<string>(ColName)).ToArray();
So with this approach,you only need to loop through columns once:
sample code:
for (int i = 0; i < Summary.Columns.Count; i++)
{
string ColName = Summary.Columns[i].ColumnName;
var datatype = Summary.Columns[i].DataType;
if (datatype==typeof(string))
{
string[] ColArray = Summary.AsEnumerable().Select(rw => rw.Field<string>(ColName)).ToArray();
JmpDT.GetColumn(ColName).SetDataVector(ColArray);
}
else if (datatype == typeof(double))
{
double[] ColArray = Summary.AsEnumerable().Select(rw => rw.Field<double>(ColName)).ToArray();
jmpDT.GetColumn(ColName).SetDataVector(ColArray);
}
else if (datatype == typeof(int))
{
int[] ColArray = Summary.AsEnumerable().Select(rw => rw.Field<int>(ColName)).ToArray();
jmpDT.GetColumn(ColName).SetDataVector(ColArray);
}
else if (datatype == typeof(float))
{
float[] ColArray = Summary.AsEnumerable().Select(rw => rw.Field<float>(ColName)).ToArray();
jmpDT.GetColumn(ColName).SetDataVector(ColArray);
}
}
While this solution works (and is orders of magnitude faster than using "SetCellVal" method, it still is almost twice as slow as pasting a tab delimted string from windows clipboard for my application.
I did time trials: ~9000 rows and 175 columns
pasting clipboard ~2.5s, while technique above ~4.5s
So I would like to request in the future a more direct method to bring data into JMP from C# datatables.
I would use the windows clipboard, but even with error trapping, the Windows clipboard can be flakey and unreiliable on some people PC's hence would not like to use that technique.
FYI WIndows clipboard would be populated with a tab delimited string, then use this code to get data into JMP.
command = "dts << Bring Window To Front << Clear Column Selection << clear select; dts=currentdatatable();";
myJMP.RunCommand(command);
command = "main menu(\"Paste With Column Names\");";
myJMP.RunCommand(command);
It would be nice if this pasting could be done from something other than the windows clipboard. (i.e. a tab delimited string passed from a method). Or a method that can take datatable variable directly and convert to JMP datatable.
Thank you for your consideration,
Chris