I am very new in developing apps with C# for WP 8.1 Silverlight.
I developed an app to display data from a csv-file.
The data is displayed in a grid within a scrollviewer element with 7 columns.
All works fine. But when the app gets more then 600 lines from the csv-file the app crashes with an out of Memory exception.
How can I avoid this? It should be no problem to display 600 lines of text in a grid.
See my code:
//insert lines:
//Row create:
reihe1 = new RowDefinition();
reihe1.Height = new GridLength(zeilenhoehe);
grid_umsatzdetail.RowDefinitions.Add(reihe1);
reihe1 = null;
//Columns create:
//first column date:
textblock_name = dateizeile + "|" + index_daten + "|" + "0";
TextBlock textblock_new_datum = new TextBlock();
textblock_new_datum.Name = textblock_name;
textblock_new_datum.Height = zeilenhoehe;
textblock_new_datum.Width = Double.NaN;
textblock_new_datum.FontSize = schriftgroesse;
textblock_new_datum.Text = " " + teile[0] + " ";
Grid.SetRow(textblock_new_datum, zaehler_reihe);
Grid.SetColumn(textblock_new_datum, 0);
grid_umsatzdetail.Children.Add(textblock_new_datum);
textblock_new_datum = null;
//border insert into grid:
rand = new Border();
rand.BorderThickness = new Thickness(1);
rand.BorderBrush = new SolidColorBrush(Colors.White);
rand.Width = Double.NaN;
rand.Height = zeilenhoehe_head;
Grid.SetRow(rand, zaehler_reihe);
Grid.SetColumn(rand, 0);
grid_umsatzdetail.Children.Add(rand);
rand = null;
//second column amount:
... same coding as above for every column ...
I am really happy for any tips!
Related
I'm working on stimulsoft 2017.2.2 and C# (.NET4).
I have designed a report with footer and header , It is A4 and there is a table in it , based on stimulsofts method(DataGrid) to create a table at runtime I managed to change it to a report which accepts DataTable and everything works just fine on an empty project (.mrt file).
There is a table so i want to customize it there , Call it and customize it at runtime.
The problem is when I want to add this to my own file (.mrt) the table is empty , it only has 1 column and the rows are fine , the whole table is empty but the design is visible.
So I will really appreciate If you could help me to sort this problem out.
My method looks like this :
private void PrintDataTable(string StiTableName, string DataSourceName, DataTable dataTable, StiReport report)
{
DataView dataView = new DataView(dataTable);
report.Compile();
//script lang
report.ScriptLanguage = StiReportLanguageType.CSharp;
// Add data to datastore
report.RegData(DataSourceName, dataView);
// Fill dictionary
report.Dictionary.Synchronize();
//StiPage page = report.Pages.Items[0];
// Create Table
StiTable table = (StiTable)report[StiTableName];
//StiTable table = (StiTable)report.GetComponentByName(StiTableName);
table.DataSourceName = DataSourceName;
table.AutoWidthType = StiTableAutoWidthType.LastColumns;
table.ColumnCount = dataTable.Columns.Count;
table.RowCount = 3;
table.HeaderRowsCount = 1;
table.FooterRowsCount = 1;
//table.Width = page.Width;
//table.Height = page.GridSize * 12;
//table.DataSourceName = DataSourceName;
table.CreateCell();
table.TableStyleFX = new StiTable21StyleFX();
table.TableStyle = Stimulsoft.Report.Components.Table.StiTableStyle.Style59;
int indexHeaderCell = 0;
int indexDataCell = dataTable.Columns.Count;
//int indexDataCell = dataTable.Columns.Count;
foreach (DataColumn column in dataView.Table.Columns)
{
// Set text on header
StiTableCell headerCell = table.Components[indexHeaderCell] as StiTableCell;
headerCell.Text.Value = column.Caption;
headerCell.HorAlignment = StiTextHorAlignment.Center;
headerCell.VertAlignment = StiVertAlignment.Center;
StiTableCell dataCell = table.Components[indexDataCell] as StiTableCell;
dataCell.HorAlignment = StiTextHorAlignment.Center;
headerCell.VertAlignment = StiVertAlignment.Center;
dataCell.Text.Value = "{" + DataSourceName + "." + Stimulsoft.Report.CodeDom.StiCodeDomSerializator.ReplaceSymbols(column.ColumnName) + "}";
dataCell.Border = new StiBorder(StiBorderSides.All, Color.FromArgb(32, 178, 170), 1, StiPenStyle.Dash);
indexHeaderCell++;
indexDataCell++;
}
// Set text on footer
StiTableCell footerCell = table.Components[table.Components.Count - 1] as StiTableCell;
footerCell.Text.Value = "Count - {Count()}";
footerCell.Font = new Font("Arial", 15, FontStyle.Bold);
footerCell.VertAlignment = StiVertAlignment.Center;
footerCell.HorAlignment = StiTextHorAlignment.Center;
}
Thank you.
I'ts been 2 weeks and I even tried other ways like
report.GetComponentByName("Table1");
and still nothing ,
I really need this in short time ,
Will appreiciate your help.
Thank you.
This is a HOTFIX:
private void PrintTableFine(StiReport report ,DataTable dataTable)
{
DataView dataView = new DataView(dataTable);
report.Load(Application.StartupPath + "\\A4 Portrait.mrt");
report.ScriptLanguage = StiReportLanguageType.CSharp;
// Add data to datastore
report.RegData("view", dataView);
// Fill dictionary
report.Dictionary.Synchronize();
StiPage page = report.Pages.Items[0];
// Create Table
StiTable table = new StiTable();
table.Name = "Table1";
table.AutoWidthType = StiTableAutoWidthType.LastColumns;
table.ColumnCount = dataTable.Columns.Count;
table.RowCount = 3;
table.HeaderRowsCount = 1;
table.FooterRowsCount = 1;
table.Width = page.Width;
table.Height = page.GridSize * 12;
table.DataSourceName = "view" + dataView.Table.TableName;
page.Components.Add(table);
table.CreateCell();
table.TableStyleFX = new StiTable21StyleFX();
table.TableStyle = Stimulsoft.Report.Components.Table.StiTableStyle.Style31;
int indexHeaderCell = 0;
int indexDataCell = dataTable.Columns.Count;
foreach (DataColumn column in dataView.Table.Columns)
{
// Set text on header
StiTableCell headerCell = table.Components[indexHeaderCell] as StiTableCell;
headerCell.Text.Value = column.Caption;
headerCell.Font = new Font("IRANSans(FaNum)", 10, FontStyle.Bold);
headerCell.HorAlignment = StiTextHorAlignment.Center;
headerCell.VertAlignment = StiVertAlignment.Center;
headerCell.Border = new StiBorder(StiBorderSides.All, Color.FromArgb(0, 0, 0), 1, StiPenStyle.Dash);
StiTableCell dataCell = table.Components[indexDataCell] as StiTableCell;
dataCell.Text.Value = "{view" + dataView.Table.TableName + "." +
Stimulsoft.Report.CodeDom.StiCodeDomSerializator.ReplaceSymbols(column.ColumnName) + "}";
dataCell.Font = new Font("IRANSans(FaNum)", 10, FontStyle.Regular);
dataCell.HorAlignment = StiTextHorAlignment.Center;
dataCell.VertAlignment = StiVertAlignment.Center;
dataCell.Border = new StiBorder(StiBorderSides.All, Color.FromArgb(0, 0, 0), 1, StiPenStyle.Dash);
indexHeaderCell++;
indexDataCell++;
}
// Set text on footer
StiTableCell footerCell = table.Components[table.Components.Count - 1] as StiTableCell;
//footerCell.Text.Value = "Count - {Count()}";
footerCell.Font = new Font("IRANSans(FaNum)", 10, FontStyle.Regular);
footerCell.VertAlignment = StiVertAlignment.Center;
footerCell.HorAlignment = StiTextHorAlignment.Center;
}
Actually it creates a table.
Please remember , to use it like this :
DataTable dt = new DataTable();
StiReport report = new StiReport();
//Reminder: compiling is after the table
//table:
PrintTableFine(report,dt);
report.Compile();
//adding a variable:
report["Variable"] = "var1ا";
report.Render(false);
report.Show();
Just give it a DataTable and it will create a table with header and footer.
Reminder: the report which your adding this table to SHOULD NOT HAVE A (Sti)TABLE IN IT(in the design).
I have been developing an application using winforms c# .net 4.0.
this application use datagridview and i add combobox + textbox to the datagridview.
During binddata and resizing actions, a black rectangle will draw in the bottom portion of the datagridview.
see the image of the problems
it works perfectly on standard DPI, but problem on the high DPI.
here is the some of my code to binddata and resizing.
using (Class1.Connection = new OleDbConnection(Class1.ConnString))
{
string sql1 = "SELECT tbAuditDetails.AuditNo, tbAuditQuestions.AutoSubcontent, tbAuditQuestions.AutoID, tbAuditQuestions.Questions, tbScore.Description, tbAuditDetails.QuestionID, tbAuditQuestions.QuestAutoID, tbAuditDetails.ScoreID, tbScore.Score, tbAuditQuestions.SubContentID, tbAuditDetails.ProfileID, tbAuditDetails.ScoreRanges, tbAuditDetails.Comments FROM (tbAuditDetails INNER JOIN tbAuditQuestions ON tbAuditDetails.QuestionID = tbAuditQuestions.QuestionID) INNER JOIN tbScore ON tbAuditDetails.ScoreID = tbScore.ScoreID WHERE (([tbAuditDetails.AuditNo] = " + Class1.detailsauditno + ") AND ([tbAuditQuestions.AutoSubcontent] = '" + newautosubcontentid + "') AND ([tbAuditDetails.ProfileID] = " + proid + ")) ORDER BY [tbAuditQuestions.QuestAutoID], [tbAuditDetails.QuestionID]";
Class1.Connection.Open();
oleCommand = new OleDbCommand(sql1, Class1.Connection);
oleAdapter = new OleDbDataAdapter(oleCommand);
oleBuilder = new OleDbCommandBuilder(oleAdapter);
oleDs = new DataSet();
oleAdapter.Fill(oleDs, "tbAuditDetails");
oleTable = oleDs.Tables["tbAuditDetails"];
Class1.Connection.Close();
dataGridView1.DataSource = oleDs.Tables["tbAuditDetails"];
//SET DATAGRIDVIEW
dataGridView1.Columns[0].Visible = false;
dataGridView1.Columns[4].Visible = false;
dataGridView1.Columns[5].Visible = false;
dataGridView1.Columns[6].Visible = false;
dataGridView1.Columns[7].Visible = false;
dataGridView1.Columns[8].Visible = false;
dataGridView1.Columns[9].Visible = false;
dataGridView1.Columns[10].Visible = false;
dataGridView1.Columns[1].HeaderText = " ";
dataGridView1.Columns[1].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridView1.Columns[1].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight;
dataGridView1.Columns[1].ReadOnly = true;
dataGridView1.Columns[1].Width = 40;
dataGridView1.Columns[2].HeaderText = "ID";
dataGridView1.Columns[2].Width = 40;
dataGridView1.Columns[2].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridView1.Columns[2].ReadOnly = true;
dataGridView1.Columns[3].Width = 600;
dataGridView1.Columns[3].ReadOnly = true;
dataGridView1.Columns[3].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.Columns[11].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
dataGridView1.Columns[11].HeaderText = "Score";
dataGridView1.Columns[12].Width = 220;
for (int iii = 0; iii < dataGridView1.Rows.Count; iii++)
{
DataGridViewComboBoxCell ComboBoxCell2 = new DataGridViewComboBoxCell();
ComboBoxCell2.Items.Add("0");
ComboBoxCell2.Items.Add("10");
ComboBoxCell2.Items.Add("20");
ComboBoxCell2.Items.Add("30");
ComboBoxCell2.Items.Add("40");
ComboBoxCell2.Items.Add("50");
ComboBoxCell2.Items.Add("60");
ComboBoxCell2.Items.Add("70");
ComboBoxCell2.Items.Add("80");
ComboBoxCell2.Items.Add("90");
ComboBoxCell2.Items.Add("100");
//ComboBoxCell.Items.AddRange(new string[] { "YES", "SOME", "NO", "N/A" });
ComboBoxCell2.FlatStyle = FlatStyle.Standard;
this.dataGridView1[11, iii] = ComboBoxCell2;
ComboBoxCell2.Dispose();
}
}
Any suggestions?
I don't know this is the right solution or not...
BUT, it fix my problem.
Here :
Right click on the .exe program (after you build) and Disable HIGH DPI
I wanted to display no of course json objects in each textbox
but as they are unpredictable number of objects therefore i created textbox on the fly using this code
List<Course> Cdata = JsonConvert.DeserializeObject<List<Course>>(App.data);
TextBox[] Tblock = new TextBox[Cdata.Count];
double top = 0; int i = 0;
foreach (Course de in Cdata)
{
result += de.course_name + "\r\n";
result += "Total Absents = " + de.absents;
result += " + " + de.presents;
result += " = " + de.sessions + "\r\n\r\n\r\n";
Tblock[i] = new TextBox();
Tblock[i].Text = result;
Tblock[i].AcceptsReturn = true;
Tblock[i].TextWrapping = TextWrapping.Wrap;
Tblock[i].Width = 475;
Tblock[i].Height = 270;
Tblock[i].IsReadOnly = true;
Tblock[i].Margin =new Thickness (0,top,0,0);
Tblock[i].Visibility = System.Windows.Visibility.Visible;
Tblock[i].VerticalAlignment = System.Windows.VerticalAlignment.Top;
top += 270; i++;
result = "";
}
Now when i debug my app data it is working as its supposed to the only problem is textbox
never display on View
and i haven't coded any textbox in Xaml file of view
Thanks in Advance
You have to add the Textboxes to any existing Panel (generally to Grid or StackPanel) in the XAML as shown below
StackPanel sp = new StackPanel(); //Create stack panel before foreach loop
foreach (Course de in Cdata)
{
//your code which you shown above
sp.Children.Add(Tblock[i]); //Add all the Textboxes to the stackpanel
}
ContentPanel.Children.Add(sp); //And add the above stackpanel to the existing Grid named ContentPanel
By the way, I suggest you to use a ListBox with ItemTemplate to bind the data instead of creating the TextBoxes as shown above.
Also, I don't understand why you have choosen TextBox instead of TextBlock to display data
I want to resize image after I insert it on excel sheet. I'm inserting picture like this:
Excel.Pictures p = myWorkSheet.Pictures(System.Type.Missing) as Excel.Pictures;
Excel.Picture pic = null;
pic = p.Insert(path + pic_name + ".png", System.Type.Missing);
pic.Left = Convert.ToDouble(picPosition.Left);
pic.Top = picPosition.Top;
I've tried to resize the picture before insert but it looses its quality.
Solved!!! I've just put next three lines in code above:
pic.ShapeRange.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoCTrue;
pic.ShapeRange.Width = 170;
pic.ShapeRange.Height = 170;
So, now it looks like this:
Excel.Pictures p = myWorkSheet.Pictures(System.Type.Missing) as Excel.Pictures;
Excel.Picture pic = null;
pic = p.Insert(path + pic_name + ".png", System.Type.Missing);
pic.ShapeRange.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoCTrue;
pic.ShapeRange.Width = 170;
pic.ShapeRange.Height = 170;
pic.Left = Convert.ToDouble(picPosition.Left);
pic.Top = picPosition.Top;
and it works great.
I have a problem I seem to stumble over all the time, I have a Drop Down box and you can select a number which creates x number of textboxes with images buttons its for a survey it the image buttons are used to create "Sub-Answers" so they can have answers to answers so my question is I need to when they hit the image button to create a textbox under the orginal textbox here is the code.
for (Int32 i = 1; i <= NumberOfAnwsers; i++)
{
Literal l1 = new Literal();
l1.Text = "<tr><td>Answer " + i + " text.</td><td>";
TextBox tb = new TextBox();
tb.ID = "TextBoxAnswer" + i;
tb.EnableViewState = false;
tb.Width = 300;
Literal l3 = new Literal();
l3.Text = "</td><td>";
Literal l2 = new Literal();
l2.Text = "</td></tr>";
RadColorPicker CPI = new RadColorPicker();
CPI.PaletteModes = PaletteModes.WebPalette;
CPI.ID = "RadColorPicker" + i;
CPI.ShowIcon = true;
CPI.SelectedColor = System.Drawing.Color.Black;
ImageButton IBVideo = new ImageButton();
IBVideo.ID = "IBVideo" + i;
IBVideo.ImageUrl = "/images/video-icon.jpg";
IBVideo.ToolTip = "Add Video";
IBVideo.Height = 20;
IBVideo.Width = 20;
ImageButton IBAdd = new ImageButton();
IBAdd.ID = "IBAdd" + i;
IBAdd.ImageUrl = "/images/add-icon.png";
IBAdd.ToolTip = "Add Sub-Answers";
//IBAdd.OnClientClick = "showDialog(" + i + ");return false;";
IBAdd.Height = 20;
IBAdd.Width = 20;
//Add Textbox
PanelAnswersToQuestions.Controls.Add(l1);
PanelAnswersToQuestions.Controls.Add(tb);
PanelAnswersToQuestions.Controls.Add(l3);
PanelAnswersToQuestions.Controls.Add(CPI);
PanelAnswersToQuestions.Controls.Add(IBVideo);
PanelAnswersToQuestions.Controls.Add(IBAdd);
PanelAnswersToQuestions.Controls.Add(l2);
}
As you can see I just add controls to the panel, I need to know when that ImageBUtton is hit I can add a Textbox and in this case it could be more then just one textbox to it.
I hope this is clear but for some reason I dont think it is ... sorry.
I have added a radwindow and poping that up sending the Data to the partent via javascript the which created a new problem for me, I can not in javascript seem to find the dynamicly created hiddenfield
function OnClientClose(radWindow) {
var oWnd = $find("<%=RadWindowAddSubAnswer.ClientID%>");
var SubAnswerValues = oWnd.get_contentFrame().contentWindow.document.forms(0).HiddenFieldSubAnswers.value;
alert(SubAnswerValues);
var AnswerID = oWnd.get_contentFrame().contentWindow.document.forms(0).HiddenFieldAnswerID.value;
alert(AnswerID);
var HiddenName = "HiddenFieldSubAnswers" + AnswerID;
alert(HiddenName);
document.getElementById(HiddenName).value = SubAnswerValues;
$get("DivSubAnswers" + AnswerID).innerHTML = SubAnswerValues;
}
The "document.getElementById(HiddenName).value = SubAnswerValues;" seems to never be found, I also tried $get(HiddenName).value = SubAnswerValues; that does not seem to work either both come back as null as for the code behind its:
HiddenField HFSubAnswers = new HiddenField();
HFSubAnswers.ID = "HiddenFieldSubAnswers" + i;
HFSubAnswers.Value = "0";
Im not sure if I got your question right but if you need to dynamically add controls on a Page here is what I can say.
Before adding your control I guess you need to find the control where you need to add it on, Add the control then assign the properties.
PlaceHolder myPlaceHolder = (PlaceHolder)Page.FindControl("PlaceHolder1");
myPlaceHolder.Controls.Add(myButton);
myButton.Text = "Hello World";
For a more detailed expalnation go here http://anyrest.wordpress.com/2010/04/06/dynamically-removing-controls-in-a-parent-page-from-a-child-control/