Click here to Skip to main content
15,890,982 members
Home / Discussions / C#
   

C#

 
AnswerRe: how can I search eventlog for a specific string Pin
Abhijit Jana27-Jun-08 21:52
professionalAbhijit Jana27-Jun-08 21:52 
Questiontreeview node problem Pin
ginji2027-Jun-08 19:51
ginji2027-Jun-08 19:51 
AnswerRe: treeview node problem Pin
Christian Graus27-Jun-08 20:19
protectorChristian Graus27-Jun-08 20:19 
AnswerRe: treeview node problem Pin
wasimsharp27-Jun-08 23:12
wasimsharp27-Jun-08 23:12 
Questionhow to make this condition true c# registration code Pin
theredonion27-Jun-08 19:47
theredonion27-Jun-08 19:47 
AnswerRe: how to make this condition true c# registration code Pin
Christian Graus27-Jun-08 20:02
protectorChristian Graus27-Jun-08 20:02 
AnswerRe: how to make this condition true c# registration code Pin
Christian Graus27-Jun-08 21:07
protectorChristian Graus27-Jun-08 21:07 
Questionprint concept very urgent help me Pin
cse.vidhya27-Jun-08 19:27
cse.vidhya27-Jun-08 19:27 
hi,



i am print concept to print the dtagrid rows.....


i am using c# coding......


while taking the print i am getting output as(givn below)....



Pepsi 500ml £1.09


coke 500ml £1.09


Fanta 500ml £1.09


Sprite 500ml .99p

but my uotput should be like the given below......


Pepsi 500ml £1.09 coke 500ml £1.09


Fanta 500ml £1.09 Sprite 500ml .99p

tell me where i have to change my coding paart:

my coding is;

public class DataGridPrinter
{

private PrintDocument ThePrintDocument;
private DataTable TheTable;
private DataGridView TheDataGrid;

public int RowCount = 0; // current count of rows;
//private const int kVerticalCellLeeway = 10;

public int PageNumber = 1;
public ArrayList Lines = new ArrayList();

int PageWidth;
int PageHeight;
int TopMargin;
int BottomMargin;



public DataGridPrinter(DataGridView aGrid, PrintDocument aPrintDocument, DataTable aTable)
{
//
// TODO: Add constructor logic here
//

TheDataGrid = aGrid;
ThePrintDocument = aPrintDocument;
TheTable = aTable;
// TheTable.Columns.RemoveAt(3);

PageWidth = 350;
TopMargin = 30;
// PageWidth = ThePrintDocument.DefaultPageSettings.PaperSize.Width;
PageHeight = ThePrintDocument.DefaultPageSettings.PaperSize.Height;
//TopMargin = ThePrintDocument.DefaultPageSettings.Margins.Top;
//TopMargin = 100;
BottomMargin = ThePrintDocument.DefaultPageSettings.Margins.Bottom;


}

public void DrawHeader(Graphics g, int ff)
{
//SolidBrush ForeBrush = new SolidBrush(TheDataGrid.HeaderForeColor);
//SolidBrush BackBrush = new SolidBrush(TheDataGrid.HeaderBackColor);
//Pen TheLinePen = new Pen(TheDataGrid.GridLineColor, 1);
StringFormat cellformat = new StringFormat();
cellformat.Trimming = StringTrimming.EllipsisCharacter;

cellformat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit | StringFormatFlags.NoClip;


int ht = ff + 2;

int columnwidth = 30;

int initialRowCount = RowCount;

// draw the table header
//float startxposition = TheDataGrid.Location.X;
float startxposition = 30;

RectangleF nextcellbounds = new RectangleF(0, 0, 0, 0);

RectangleF HeaderBounds = new RectangleF(0, 0, 0, 0);

HeaderBounds.X = TheDataGrid.Location.X;
HeaderBounds.Y = TheDataGrid.Location.Y + TopMargin + (RowCount - initialRowCount) * (TheDataGrid.Font.SizeInPoints + ht);
HeaderBounds.Height = TheDataGrid.Font.SizeInPoints + ht;
HeaderBounds.Width = PageWidth;

//g.FillRectangle(BackBrush, HeaderBounds);

for (int k = 0; k < TheTable.Columns.Count; k++)
{
string nextcolumn = TheTable.Columns[k].ToString();


//Command Line

//RectangleF cellbounds = new RectangleF(startxposition, TheDataGrid.Location.Y + TopMargin + (RowCount - initialRowCount) * (TheDataGrid.Font.SizeInPoints + kVerticalCellLeeway),
// columnwidth,
// TheDataGrid.HeaderFont.SizeInPoints + kVerticalCellLeeway);
//nextcellbounds = cellbounds;

//if (startxposition + columnwidth <= PageWidth)
//{
// g.DrawString(nextcolumn, TheDataGrid.HeaderFont, ForeBrush, cellbounds, cellformat);
//}

//startxposition = startxposition + columnwidth;

//Command LIne
}

//if (TheDataGrid.GridLineStyle != DataGridLineStyle.None)
//g.DrawLine(TheLinePen, TheDataGrid.Location.X, nextcellbounds.Bottom, PageWidth, nextcellbounds.Bottom);
}

public bool DrawRows(Graphics g, int fz)
{
int lastRowBottom = TopMargin;
int hh = fz + 60;
try
{
SolidBrush ForeBrush = new SolidBrush(TheDataGrid.ForeColor);
SolidBrush BackBrush = new SolidBrush(TheDataGrid.BackColor);
//SolidBrush AlternatingBackBrush = new SolidBrush(TheDataGrid.AlternatingBackColor);
//Pen TheLinePen = new Pen(TheDataGrid.GridLineColor, 1);
StringFormat cellformat = new StringFormat();
cellformat.Trimming = StringTrimming.EllipsisCharacter;
cellformat.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.LineLimit;

//int columnwidth = PageWidth/TheTable.Columns.Count;
int columnwidth = (PageWidth / TheTable.Columns.Count);

//columnwidth = 100;

int initialRowCount = RowCount;

RectangleF RowBounds = new RectangleF(0, 0, 0, 0);

// draw vertical lines


Font printFont = new Font("Arial", fz);


// draw the rows of the table
for (int i = initialRowCount; i < TheTable.Rows.Count; i++)
{
DataRow dr = TheTable.Rows[i];

int startxposition = TheDataGrid.Location.X;
//startxposition = 20;

RowBounds.X = TheDataGrid.Location.X;
RowBounds.Y = TheDataGrid.Location.Y + TopMargin + ((RowCount - initialRowCount) + 1) * (TheDataGrid.Font.SizeInPoints + hh);
RowBounds.Height = TheDataGrid.Font.SizeInPoints + hh;
RowBounds.Width = PageWidth;
Lines.Add(RowBounds.Bottom);

if (i % 2 == 0)
{
g.FillRectangle(BackBrush, RowBounds);
}
else
{
//g.FillRectangle(AlternatingBackBrush, RowBounds);
}


for (int j = 0; j < TheTable.Columns.Count; j++)
{
RectangleF cellbounds = new RectangleF(startxposition,
TheDataGrid.Location.Y + TopMargin + ((RowCount - initialRowCount) + 1) * (TheDataGrid.Font.SizeInPoints + hh),
columnwidth,
TheDataGrid.Font.SizeInPoints + hh);
//200 + kVerticalCellLeeway);


if (startxposition + columnwidth <= PageWidth)
{
g.DrawString(dr[j].ToString(), printFont, ForeBrush, cellbounds, cellformat);
lastRowBottom = (int)cellbounds.Bottom;
}

startxposition = startxposition + columnwidth;
}

RowCount++;

if (RowCount + 1 * (TheDataGrid.Font.SizeInPoints + fz) > (PageHeight * PageNumber) - (BottomMargin + TopMargin))
{
DrawHorizontalLines(g, Lines);

//DrawVerticalGridLines(g, TheLinePen, columnwidth, lastRowBottom);
return true;
}


}

DrawHorizontalLines(g, Lines);
//DrawVerticalGridLines(g, TheLinePen, columnwidth, lastRowBottom);
return false;

}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
return false;
}

}

void DrawHorizontalLines(Graphics g, ArrayList lines)
{
//Pen TheLinePen = new Pen(TheDataGrid.GridLineColor, 1);

//if (TheDataGrid.GridLineStyle == DataGridLineStyle.None)
return;

for (int i = 0; i < lines.Count; i++)
{
// g.DrawLine(TheLinePen, TheDataGrid.Location.X, (float)lines[i], PageWidth, (float)lines[i]);
}
}

void DrawVerticalGridLines(Graphics g, Pen TheLinePen, int columnwidth, int bottom)
{
//if (TheDataGrid.GridLineStyle == DataGridLineStyle.None)
return;

for (int k = 0; k < TheTable.Columns.Count; k++)
{
g.DrawLine(TheLinePen, TheDataGrid.Location.X + k * columnwidth,
TheDataGrid.Location.Y + TopMargin,
TheDataGrid.Location.X + k * columnwidth,
bottom);
}
}


public bool DrawDataGrid(Graphics g, int ff)
{

try
{

DrawHeader(g, ff);
bool bContinue = DrawRows(g, ff);
return bContinue;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
return false;
}

}

}
AnswerRe: print concept very urgent help me Pin
Christian Graus27-Jun-08 19:46
protectorChristian Graus27-Jun-08 19:46 
GeneralRe: print concept very urgent help me Pin
cse.vidhya27-Jun-08 21:02
cse.vidhya27-Jun-08 21:02 
GeneralRe: print concept very urgent help me Pin
Christian Graus27-Jun-08 21:06
protectorChristian Graus27-Jun-08 21:06 
Questionasp.net 3.5 Pin
arkiboys27-Jun-08 18:37
arkiboys27-Jun-08 18:37 
AnswerRe: asp.net 3.5 Pin
Abhijit Jana27-Jun-08 21:23
professionalAbhijit Jana27-Jun-08 21:23 
AnswerRe: asp.net 3.5 Pin
wasimsharp27-Jun-08 23:14
wasimsharp27-Jun-08 23:14 
QuestionRegular Expressions - State Machine UML Diagram? Pin
Leblanc Meneses27-Jun-08 16:53
Leblanc Meneses27-Jun-08 16:53 
AnswerRe: Regular Expressions - State Machine UML Diagram? Pin
Christian Graus27-Jun-08 17:32
protectorChristian Graus27-Jun-08 17:32 
QuestionDataRow question Pin
David Loring27-Jun-08 16:24
David Loring27-Jun-08 16:24 
AnswerRe: DataRow question Pin
Karthik Kalyanasundaram27-Jun-08 16:30
Karthik Kalyanasundaram27-Jun-08 16:30 
GeneralRe: DataRow question Pin
David Loring27-Jun-08 16:33
David Loring27-Jun-08 16:33 
QuestionWhat is it called when your class has a root collection and how do you do it in C#? Pin
qmuffs27-Jun-08 16:15
qmuffs27-Jun-08 16:15 
AnswerRe: What is it called when your class has a root collection and how do you do it in C#? Pin
Paul Conrad27-Jun-08 16:22
professionalPaul Conrad27-Jun-08 16:22 
GeneralRe: What is it called when your class has a root collection and how do you do it in C#? Pin
qmuffs27-Jun-08 16:30
qmuffs27-Jun-08 16:30 
AnswerRe: What is it called when your class has a root collection and how do you do it in C#? Pin
Karthik Kalyanasundaram27-Jun-08 16:37
Karthik Kalyanasundaram27-Jun-08 16:37 
GeneralRe: What is it called when your class has a root collection and how do you do it in C#? Pin
qmuffs27-Jun-08 16:41
qmuffs27-Jun-08 16:41 
QuestionADO.net locks out SQL2000 user account under load Pin
Mr Jen Withers27-Jun-08 11:11
Mr Jen Withers27-Jun-08 11:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.