I want to save a dataset table to an excel file just like the grid exporter. I want to dynamically create the grid without displaying anything and use the grid exporter to export it. The code below runs and there are multiple rows in the dataset with just 1 table. The wg.Refresh(); does not fill the grid. So I am asking how do I get the grid filled with the data. Again, the Grid is not on a form.
Infragistics.Win.UltraWinGrid.
();
wg.DataSource = dsInput;
wg.DataMember =
;
wg.Refresh();
band = wg.DisplayLayout.Bands[0];
//foreach (Infragistics.Win.UltraWinGrid.UltraGridBand band in wg.Rows.Band)
wg.Rows)
{
count = band.Columns.Count - 1; count >= 0; count--)
band.Columns[count].PerformAutoResize(Infragistics.Win.UltraWinGrid.
.AllRowsInBand);
}
Infragistics.Win.UltraWinGrid.ExcelExport.
ux.Export(wg,
);
Hello Rookertrusted,
I am not exactly sure what your scenario is, but if you still use a Windows Forms application you could set the BindingContext of the UltraGrid to one from the Form, or if you are using a console application you could try the second one like the following:
ultraGrid1.BindingContext = this.BindingContext;ultraGrid1.BindingContext = new BindingContext();
Also if you need to resize the columns of the UltraGrid you could try doing so directly like:
ultraGrid1.DisplayLayout.PerformAutoResizeColumns(true, PerformAutoSizeType.AllRowsInBand);If i missunderstood you in a way please feel free to let me know.
The grid is now filled with data with the line: mwg.BindingContext = new BindingContext (); which is perfect, but the line: wg.DisplayLayout.PerformAutoResizeColumns(true, PerformAutoSizeType.AllRowsInBand); does not expand all the columns in the grid. This is a console app and does not need to display the grid. Just need to export it to an excel file.
Infragistics.Win.UltraWinGrid.UltraGrid wg = new Infragistics.Win.UltraWinGrid.UltraGrid();
"objTable";
wg.BindingContext =
new BindingContext();
wg.DisplayLayout.PerformAutoResizeColumns(
true, PerformAutoSizeType.AllRowsInBand);
UltraGridExcelExporter ux = new Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter();
@"c:\rosslrooker.xls");
Hello RookerTrusted,
If you mean by "Expand" to make your column wider in order to fit the text inside it, you could set the following for your UltraGrid, prior performing the column resize:
wg.DisplayLayout.Override.AllowColSizing = AllowColSizing.Free;If you have any other questions please feel free to contact us.
That was perfect. Just one other question..... Based on the logic, how do I run some code on the IntializeRow event. IE... I can't double click on this event because it doesn't actually display the grid.
What you could do here is to subscribe for this event prior setting the DataSource to your UltraGrid like:
wg.InitializeRow += and press Tab key twise;In the handler of the event you could set the desired logic and it will apply for your UltraGrid.If you have any other questions with this matter please feel free to let us know.
Not sure what you mean to press the tab key twice?
Also assuming I want to display MessageBox.Show("It worked") on the InitializeRow, what code would it take?
By this I meant the following:
Please type "wg.InitializeRow +=" and the Intelisense will provide you the ability to click the Tab key from the key board, in order to finish the subscription of the event for you, and if you click the Tab key from the keyboard one more time the Visual Studio will create also the handler for you as well.
If the procedure is completed correctly you would see would be like the following:
wg.InitializeRow += new Infragistics.Win.UltraWinGrid.InitializeRowEventHandler(ug_InitializeRow);
static void ug_InitializeRow(object sender, InitializeRowEventArgs e) { throw new NotImplementedException(); }So please remove the "throw new NotImplementedException(); " and add there your code instead:
MessageBox.Show("It worked");Please note that your message box will be shown two time more than the rows that your DataTable contains, the first time this event will fire for each UltraGridRow in the UltraGrid, and this event will fire for each row again because of the Exporter.If you need any other assistance with this matter please feel free to let me know.
Hello Rookertrusted,I am still following this forum thread.Please feel free to let me know if you have any other questions with this matter.
I have verified that you could set the desired styles to your ultraGrid columns, prior exporting the UltraGrid to excel in order to be able to have to all text visible in the excel.
For your dateTime column please set the Style to of column through the Bands[0] object to DateTime, and for your Boolean column set the column style to be .Edit.
Please feel free to let me know if there is any other questions with this matter.