I am using DGVPrinter class for printing my windows form data. after gridview unable to print any text
DGVPrinter printer = new DGVPrinter();
Bitmap bitmap1 = new Bitmap(#"D:\Aur.jpg");
DGVPrinter.ImbeddedImage img1 = new DGVPrinter.ImbeddedImage();
img1.theImage = bitmap1; img1.ImageX = 3; img1.ImageY = 3;
img1.ImageAlignment = DGVPrinter.Alignment.Right;
img1.ImageLocation = DGVPrinter.Location.Header;
printer.ImbeddedImageList.Add(img1);
printer.SubTitle = getprocess_setvalupar();
printer.SubTitleAlignment = StringAlignment.Far;
printer.SubTitleFormatFlags = StringFormatFlags.DirectionRightToLeft;
printer.PageNumbers = true;
printer.PageNumberInHeader = true;
printer.PorportionalColumns = true;
printer.HeaderCellAlignment = StringAlignment.Center;
printer.Footer = GetSignatureFooter("XXXXX Ltd");
printer.FooterSpacing = 15;
printer.PrintDataGridView(dataGridView1);
I am unable to print some text after gridview. If i tried to call function after printer.PrintDataGridView(dataGridView1);text not displaying
I am able to print subtitle before gridview in page. but unable after gridview.
Related
I have my listView in C#. It should have only one colomn, and also the attribute fo Colomns shows it has only one colomn, but the display shows two:
The ListView is initiated very simply, using
initializeComponenet()
which contains following code:
**this.lstDS.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.DirectoryHeader});**
this.lstDS.Font = new System.Drawing.Font("Microsoft Sans Serif", 12.75F);
this.lstDS.ForeColor = System.Drawing.Color.White;
this.lstDS.FullRowSelect = true;
this.lstDS.HideSelection = false;
this.lstDS.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
listViewItem1,
listViewItem2});
this.lstDS.Location = new System.Drawing.Point(75, 152);
this.lstDS.MultiSelect = false;
this.lstDS.Name = "lstDS";
this.lstDS.Size = new System.Drawing.Size(203, 138);
this.lstDS.TabIndex = 37;
this.lstDS.UseCompatibleStateImageBehavior = false;
this.lstDS.View = System.Window
if you ask yourself - here's DirectoryHeader:
private ColumnHeader DirectoryHeader;
But for any reason, it appears as if it has 2 columns.
Any idea what to check?
Thanks!
My DataGridView is showing extra columns. The application is a windows forms application. What could I be doing wrong?
public ConvertisForm1()
{
InitializeComponent();
openFileDialog.Filter = "Files| *.chm;*.htm;*.html;*.rtf;*.xls;*.xlsx;*.xps;*.doc;*.docx";
dataGridView.AutoGenerateColumns = false;
dataGridView.RowHeadersVisible = false;
dataGridView.ColumnCount = 5;
dataGridView.RowCount = 20;
//delete button
var deleteDataGridViewButtonColumn = new DataGridViewButtonColumn
{
HeaderText = "",
Name = deleteDataGridViewButtonColumnName,
Text = "X",
Width =20
};
dataGridView.Columns.Insert(DeleteColumnIndex, deleteDataGridViewButtonColumn);
dataGridView.Columns[FileNameAndPathColumnIndex].Width=250;
dataGridView.Columns[FileNameAndPathColumnIndex].HeaderText = "File Path";
//browse button
var browseDataGridViewButtonColumn = new DataGridViewButtonColumn
{
HeaderText = "",
Name = browseDataGridViewButtonColumnName,
Text = "...",
Width = 30
};
dataGridView.Columns.Insert(BrowseButtonColumnIndex, browseDataGridViewButtonColumn);
//convert to dropdown
var convertToDataGridViewComboBoxColumn = new DataGridViewComboBoxColumn
{
HeaderText = "Convert to",
Name = convertToDataGridViewComboBoxColumnName,
DataSource = new ArrayList { convertToComboBoxDefault, "pdf", "word"},
Width = 100,
DefaultCellStyle =
{
NullValue = convertToComboBoxDefault,
DataSourceNullValue = convertToComboBoxDefault
}
};
dataGridView.Columns.Insert(ConvertToFileTypeColumnIndex, convertToDataGridViewComboBoxColumn);
var convertDataGridViewButtonColumn = new DataGridViewButtonColumn
{
HeaderText = "",
Name = convertDataGridViewButtonColumnName,
Text = "Convert",
Width = 50
};
dataGridView.Columns.Insert(ConvertButtonColumnIndex, convertDataGridViewButtonColumn);
dataGridView.AllowUserToResizeColumns = false;
dataGridView.AllowUserToResizeRows = false;
#endregion
}
have you tried DataGridView1.AutoGenerateColumns = false; ?
or you can clear all Columns before adding new Columns
see link for reference: https://stackoverflow.com/a/7430993/5694113
Here is my code in TreeView in gtk. Please help me im new to gtk
Gtk.TreeViewColumn activeColumn = new Gtk.TreeViewColumn ();
activeColumn.Title = "Active";
activeColumn.Expand = true;
activeColumn.Sizing = TreeViewColumnSizing.Fixed;
activeColumn.MinWidth = 100;
Gtk.CellRendererPixbuf activeCell = new Gtk.CellRendererPixbuf ();
activeColumn.PackStart (activeCell, true);
activeColumn.AddAttribute (activeCell, "pixbuf", 6);
This is the code which i used to generate pie chart . I need to add percentage value to piechart series.Tries few ways but did not find solution.I have attached my working code output image and expected image .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms.DataVisualization.Charting;
using System.Diagnostics;
using System.Drawing;
using System.Data;
using System.Xml;
using System.Collections;
public bool GetPieChart(string XML , string Path)
{
try
{
// create chart instance
var chart = new Chart();
// set chart height and width
chart.Height = 500;
chart.Width = 600;
// Add legend to chart
chart.Legends.Add(new Legend() { Name = "Legend" });
chart.Legends[0].Font = new Font("Verdana", 10);
chart.Legends[0].Docking = Docking.Bottom;
ArrayList xAxisData = new ArrayList();
ArrayList yAxisData = new ArrayList();
XmlDocument xml = new XmlDocument();
xml.LoadXml(XML);
XmlNodeList multiLine = xml.DocumentElement.SelectNodes("/Report/PieChart/series");
// Set Chart Title
string title = xml.SelectSingleNode("/Report").Attributes["Name"].Value.ToString();
chart.Titles.Add(title);
chart.Titles[0].Font = new Font("Verdana", 12);
// Set chart properties
var chartArea = new ChartArea();
chart.ChartAreas.Add(chartArea);
Series series;
// Add data to the chart
foreach (XmlNode seriesNode in multiLine)
{
xAxisData.Clear();
yAxisData.Clear();
series = new Series();
string seriesName = seriesNode.Attributes["name"].Value.ToString();
XmlNodeList detailsList = seriesNode.SelectNodes("datapoint");
foreach (XmlNode detailNode in detailsList)
{
xAxisData.Add(detailNode.Attributes["Label"].Value.ToString());
int value;
string st = detailNode.Attributes["value"].Value.ToString();
int.TryParse(st, out value);
yAxisData.Add(value);
}
// set series properties
series.Name = seriesName;
series.ChartType = SeriesChartType.Pie;
chart.Series.Add(series);
chart.Series[seriesName].Points.DataBindXY(xAxisData, yAxisData);
chart.Series[seriesName]["PieLabelStyle"] = "Outside";
chart.Series[seriesName]["PieLineColor"] = "Black";
}
chart.SaveImage(Path, ChartImageFormat.Jpeg);
}
catch (Exception ex)
{
}
return true;
}
This is the out put from this code
This is what i expect
Guys need your help to do that ?
foreach (DataPoint p in YourChart.Series["YourSeriesName"].Points)
{
p.Label = "#PERCENT\n#VALX";
}
Finally found solution. Now works well.
chart.Series[seriesName].XValueMember = "Name";
chart.Series[seriesName].YValueMembers = "Count";
chart.Series[seriesName].IsValueShownAsLabel = true;
escape percentage sign with double percentage char. look for the sample below
Chart1.Series.Add(series);
Series series1 = Chart1.Series[0];
series1.Points.DataBindXY(xValues, yValues);
Title ti = new Title()
ti.TextStyle = TextStyle.Emboss;
ti.Text = ((yValues[0] / 100) * 100) + #"%%";//double Percentage sign
ti.Font = new Font("Times New Roman", 40, FontStyle.Bold);
ti.Position.X = 50;
ti.Position.Y = 50;
Chart1.Titles.Add(ti);
this maybe help. This code is for a Pie Chart with percentage inside the Pie and labels(strings) in the legends: Where datosSeries = List
string[] labels = datosSeries.Select(o => o.Week).ToArray();
float[] data = datosSeries.Select(o => o.ProfitSerie).ToArray();
chart2.Series.Add("Series1");
chart2.Series[0].Points.DataBindXY(labels, data);
chart2.Series[0].ChartType = SeriesChartType.Pie;
chart2.Series[0]["PieLabelStyle"] = "Outside";
chart2.Series[0].BorderWidth = 1;
chart2.Series[0].BorderColor = System.Drawing.Color.FromArgb(26, 59, 105);
chart2.Series[0].Label = "#PERCENT{P2}";
chart2.Legends.Add(new Legend("Default"));
// Add Color column
LegendCellColumn firstColumn = new LegendCellColumn();
firstColumn.ColumnType = LegendCellColumnType.SeriesSymbol;
firstColumn.HeaderText = "";
chart2.Legends["Default"].CellColumns.Add(firstColumn);
// Add name cell column
LegendCellColumn percentColumn = new LegendCellColumn();
percentColumn.Text = "#VALX";
percentColumn.HeaderText = "Tipo de Gastos";
percentColumn.Name = "nameColumn";
chart2.Legends["Default"].CellColumns.Add(percentColumn);
//Format the legend
chart2.Legends["Default"].LegendStyle = LegendStyle.Table;
chart2.Legends["Default"].TableStyle = LegendTableStyle.Tall;
chart2.Legends["Default"].DockedToChartArea = "ChartArea1";
chart2.Legends["Default"].IsDockedInsideChartArea = false;
chart2.Legends["Default"].Docking = Docking.Bottom;
I am using dbAutoTrack for generate PDF in that I have to add Table but I get the Exception like object references is not set to an instance of object
Below is my code
Table t=new Table();
Row row=new Row(t);
row.Cells.Add("ABC");
t.Rows.Add(row);
_pdfGraphics.DrawTable(100,200, t);
where _pdfGraphics is object of PDFGraphics.
Thanks in Advances
Most probably you have message like: "Not enough columns in this row to have a column span of 1." And you needed just to add them.
Workable sample:
//Initialize a new PDF Document
Document _document = new Document();
_document.Title = "Аpitron Sample";
_document.Author = "StanlyF";
_document.Creator = "АPItron LTD.";
Page page = null;
PDFGraphics graphics = null;
Table _table = new Table();
_table.Columns.Add(30);
Row row = new Row(_table);
row.Height = 25;
row.Cells.Add("ABC");
_table.Rows.Add(row);
while (_table != null)
{
//Initialize new page with default PageSize A4
page = new Page(PageSize.A4);
//Add page to document
_document.Pages.Add(page);
//Get the PDFGraphics object for drawing to the page.
graphics = page.Graphics;
_table = graphics.DrawTable(100,200, _table);
}
using(FileStream _fs = new FileStream("Table_Sample.pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write))
{
//Generate PDF to the stream
_document.Generate(_fs);
Process.Start("Table_Sample.pdf");
}
The accepted answer didn't work for me and I was still getting null reference exceptions. It turns out that the rows need to be added with a TableStyle otherwise the cells, for whatever reason, won't be generated:
StandardFonts standardfont = StandardFonts.Helvetica;
PDFFont fontSmall_reg = new PDFFont(standardfont, FontStyle.Regular);
TableStyle ts = new TableStyle(fontSmall_reg, 12, nullBorder);
Table data = new Table(ts);
data.Columns.Add(100);
data.Columns.Add(100);
Row r = new Row(data, ts);
r.Height = 25;
r.Cells.Add("Row 1 Col1");
data.add(r)
r.Cells.Add("Row 1 Col2");