|
How can I create a nested TreeView for Windows 8.1 app , data will be bind at runtime using C#? There is no Treeview Control in Windows 8.1 Development.
|
|
|
|
|
Bhola S. Parit wrote: There is no Treeview Control in Windows 8.1 Development I'm not sure if this will meet your needs, but: [^].
And, when use the term "nested," what does that mean: isn't a TreeView an example of a structure designed to express "nesting" already ?
I don't work with XAML or RT, but I know one developer who uses the GroupedGridView to represent hierarchy: [^].
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
hi
i have Datagridview
and i want to print this
so
my language is Right to left
i use Printducument but is dosnt work
please help me
tanx
-----------------
class PrintDGV
{
private static StringFormat StrFormat;
private static StringFormat StrFormatComboBox;
private static Button CellButton;
private static CheckBox CellCheckBox;
private static ComboBox CellComboBox;
private static int TotalWidth;
private static int RowPos;
private static bool NewPage;
private static int PageNo;
private static ArrayList Columnlefts = new ArrayList();
private static ArrayList ColumnWidths = new ArrayList();
private static ArrayList ColumnTypes = new ArrayList();
private static int CellHeight;
private static int RowsPerPage;
private static System.Drawing.Printing.PrintDocument printDoc =
new System.Drawing.Printing.PrintDocument();
private static string PrintTitle = "";
private static DataGridView dgv;
private static List<string> SelectedColumns = new List<string>();
private static List<string> AvailableColumns = new List<string>();
private static bool PrintAllRows = true;
private static bool FitToPageWidth = true;
private static int HeaderHeight = 0;
public static void Print_DataGridView(DataGridView dgv1)
{
PrintPreviewDialog ppvw;
try
{
dgv = dgv1;
AvailableColumns.Clear();
foreach (DataGridViewColumn c in dgv.Columns)
{
if (!c.Visible) continue;
AvailableColumns.Add(c.HeaderText);
}
FrmPrintOptions dlg = new FrmPrintOptions(AvailableColumns);
if (dlg.ShowDialog() != DialogResult.OK) return;
PrintTitle = dlg.PrintTitle;
PrintAllRows = dlg.PrintAllRows;
FitToPageWidth = dlg.FitToPageWidth;
SelectedColumns = dlg.GetSelectedColumns();
RowsPerPage = 0;
ppvw = new PrintPreviewDialog();
ppvw.Document = printDoc;
printDoc.BeginPrint +=new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
printDoc.PrintPage +=new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
if (ppvw.ShowDialog() != DialogResult.OK)
{
printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
return;
}
printDoc.Print();
printDoc.BeginPrint -= new System.Drawing.Printing.PrintEventHandler(PrintDoc_BeginPrint);
printDoc.PrintPage -= new System.Drawing.Printing.PrintPageEventHandler(PrintDoc_PrintPage);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
}
}
private static void PrintDoc_BeginPrint(object sender,
System.Drawing.Printing.PrintEventArgs e)
{
try
{
StrFormat = new StringFormat();
StrFormat.Alignment = StringAlignment.Near;
StrFormat.LineAlignment = StringAlignment.Center;
StrFormat.Trimming = StringTrimming.EllipsisCharacter;
StrFormatComboBox = new StringFormat();
StrFormatComboBox.LineAlignment = StringAlignment.Center;
StrFormatComboBox.FormatFlags = StringFormatFlags.NoWrap;
StrFormatComboBox.Trimming = StringTrimming.EllipsisCharacter;
Columnlefts.Clear();
ColumnWidths.Clear();
ColumnTypes.Clear();
CellHeight = 0;
RowsPerPage = 0;
CellButton = new Button();
CellCheckBox = new CheckBox();
CellComboBox = new ComboBox();
TotalWidth = 0;
foreach (DataGridViewColumn GridCol in dgv.Columns)
{
if (!GridCol.Visible) continue;
if (!PrintDGV.SelectedColumns.Contains(GridCol.HeaderText)) continue;
TotalWidth += GridCol.Width;
}
PageNo = 1;
NewPage = true;
RowPos = 0;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private static void PrintDoc_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
int tmpWidth, i;
int tmpTop = e.MarginBounds.Top;
int tmpleft = e.MarginBounds.Left;
try
{
if (PageNo == 1)
{
foreach (DataGridViewColumn GridCol in dgv.Columns)
{
if (!GridCol.Visible) continue;
if (!PrintDGV.SelectedColumns.Contains(GridCol.HeaderText)) continue;
if (FitToPageWidth)
tmpWidth = (int)(Math.Floor((double)((double)GridCol.Width /
(double)TotalWidth * (double)TotalWidth *
((double)e.MarginBounds.Width / (double)TotalWidth))));
else
tmpWidth = GridCol.Width;
HeaderHeight = (int)(e.Graphics.MeasureString(GridCol.HeaderText,
GridCol.InheritedStyle.Font, tmpWidth).Height) + 11;
Columnlefts.Add(tmpleft);
ColumnWidths.Add(tmpWidth);
ColumnTypes.Add(GridCol.GetType());
tmpleft += tmpWidth;
}
}
while (RowPos <= dgv.Rows.Count - 1)
{
DataGridViewRow GridRow = dgv.Rows[RowPos];
if (GridRow.IsNewRow || (!PrintAllRows && !GridRow.Selected))
{
RowPos++;
continue;
}
CellHeight = GridRow.Height;
if (tmpTop + CellHeight >= e.MarginBounds.Height + e.MarginBounds.Top)
{
DrawFooter(e, RowsPerPage);
NewPage = true;
PageNo++;
e.HasMorePages = true;
return;
}
else
{
if (NewPage)
{
e.Graphics.DrawString(PrintTitle, new Font(dgv.Font, FontStyle.Bold),
Brushes.Black, e.MarginBounds.Left, e.MarginBounds.Top -
e.Graphics.MeasureString(PrintTitle, new Font(dgv.Font,
FontStyle.Bold), e.MarginBounds.Width).Height - 13);
String s = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToShortTimeString();
e.Graphics.DrawString(s, new Font(dgv.Font, FontStyle.Bold),
Brushes.Black, e.MarginBounds.Left + (e.MarginBounds.Width -
e.Graphics.MeasureString(s, new Font(dgv.Font,
FontStyle.Bold), e.MarginBounds.Width).Width), e.MarginBounds.Top -
e.Graphics.MeasureString(PrintTitle, new Font(new Font(dgv.Font,
FontStyle.Bold), FontStyle.Bold), e.MarginBounds.Width).Height - 13);
tmpTop = e.MarginBounds.Top;
i = 0;
foreach (DataGridViewColumn GridCol in dgv.Columns)
{
if (!GridCol.Visible) continue;
if (!PrintDGV.SelectedColumns.Contains(GridCol.HeaderText))
continue;
e.Graphics.FillRectangle(new SolidBrush(Color.LightGray),
new Rectangle((int) Columnlefts[i], tmpTop,
(int)ColumnWidths[i], HeaderHeight));
e.Graphics.DrawRectangle(Pens.Black,
new Rectangle((int) Columnlefts[i], tmpTop,
(int)ColumnWidths[i], HeaderHeight));
e.Graphics.DrawString(GridCol.HeaderText, GridCol.InheritedStyle.Font,
new SolidBrush(GridCol.InheritedStyle.ForeColor),
new RectangleF((int)Columnlefts[i], tmpTop,
(int)ColumnWidths[i], HeaderHeight), StrFormat);
i++;
}
NewPage = false;
tmpTop += HeaderHeight;
}
i = 0;
foreach (DataGridViewCell Cel in GridRow.Cells)
{
if (!Cel.OwningColumn.Visible) continue;
if (!SelectedColumns.Contains(Cel.OwningColumn.HeaderText))
continue;
if (((Type) ColumnTypes[i]).Name == "DataGridViewTextBoxColumn" ||
((Type) ColumnTypes[i]).Name == "DataGridViewLinkColumn")
{
e.Graphics.DrawString(Cel.Value.ToString(), Cel.InheritedStyle.Font,
new SolidBrush(Cel.InheritedStyle.ForeColor),
new RectangleF((int)Columnlefts[i], (float)tmpTop,
(int)ColumnWidths[i], (float)CellHeight), StrFormat);
}
else if (((Type) ColumnTypes[i]).Name == "DataGridViewButtonColumn")
{
CellButton.Text = Cel.Value.ToString();
CellButton.Size = new Size((int)ColumnWidths[i], CellHeight);
Bitmap bmp =new Bitmap(CellButton.Width, CellButton.Height);
CellButton.DrawToBitmap(bmp, new Rectangle(0, 0,
bmp.Width, bmp.Height));
e.Graphics.DrawImage(bmp, new Point((int)Columnlefts[i], tmpTop));
}
else if (((Type) ColumnTypes[i]).Name == "DataGridViewCheckBoxColumn")
{
CellCheckBox.Size = new Size(14, 14);
CellCheckBox.Checked = (bool)Cel.Value;
Bitmap bmp = new Bitmap((int)ColumnWidths[i], CellHeight);
Graphics tmpGraphics = Graphics.FromImage(bmp);
tmpGraphics.FillRectangle(Brushes.White, new Rectangle(0, 0,
bmp.Width, bmp.Height));
CellCheckBox.DrawToBitmap(bmp,
new Rectangle((int)((bmp.Width - CellCheckBox.Width) / 2),
(int)((bmp.Height - CellCheckBox.Height) / 2),
CellCheckBox.Width, CellCheckBox.Height));
e.Graphics.DrawImage(bmp, new Point((int)Columnlefts[i], tmpTop));
}
else if (((Type) ColumnTypes[i]).Name == "DataGridViewComboBoxColumn")
{
CellComboBox.Size = new Size((int)ColumnWidths[i], CellHeight);
Bitmap bmp = new Bitmap(CellComboBox.Width, CellComboBox.Height);
CellComboBox.DrawToBitmap(bmp, new Rectangle(0, 0,
bmp.Width, bmp.Height));
e.Graphics.DrawImage(bmp, new Point((int)Columnlefts[i], tmpTop));
e.Graphics.DrawString(Cel.Value.ToString(), Cel.InheritedStyle.Font,
new SolidBrush(Cel.InheritedStyle.ForeColor),
new RectangleF((int)Columnlefts[i] + 1, tmpTop, (int)ColumnWidths[i]
- 16, CellHeight), StrFormatComboBox);
}
else if (((Type) ColumnTypes[i]).Name == "DataGridViewImageColumn")
{
Rectangle CelSize = new Rectangle((int)Columnlefts[i],
tmpTop, (int)ColumnWidths[i], CellHeight);
Size ImgSize = ((Image)(Cel.FormattedValue)).Size;
e.Graphics.DrawImage((Image)Cel.FormattedValue,
new Rectangle((int)Columnlefts[i] + (int)((CelSize.Width - ImgSize.Width) / 2),
tmpTop + (int)((CelSize.Height - ImgSize.Height) / 2),
((Image)(Cel.FormattedValue)).Width, ((Image)(Cel.FormattedValue)).Height));
}
e.Graphics.DrawRectangle(Pens.Black, new Rectangle((int)Columnlefts[i],
tmpTop, (int)ColumnWidths[i], CellHeight));
i++;
}
tmpTop += CellHeight;
}
RowPos++;
if (PageNo == 1) RowsPerPage++;
}
if (RowsPerPage == 0) return;
DrawFooter(e, RowsPerPage);
e.HasMorePages = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private static void DrawFooter(System.Drawing.Printing.PrintPageEventArgs e,
int RowsPerPage)
{
double cnt = 0;
if (PrintAllRows)
{
if (dgv.Rows[dgv.Rows.Count - 1].IsNewRow)
cnt = dgv.Rows.Count - 2;
else
cnt = dgv.Rows.Count - 1;
}
else
cnt = dgv.SelectedRows.Count;
string PageNum = PageNo.ToString() + " of " +
Math.Ceiling((double)(cnt / RowsPerPage)).ToString();
e.Graphics.DrawString(PageNum, dgv.Font, Brushes.Black,
e.MarginBounds.Left + (e.MarginBounds.Width -
e.Graphics.MeasureString(PageNum, dgv.Font,
e.MarginBounds.Width).Width) / 2, e.MarginBounds.Top +
e.MarginBounds.Height + 31);
}
}
|
|
|
|
|
|
Where is the problem?
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
"It doesn't work" does not really help. As is, I'd be guessing that the order in which the columns are drawn are the opposite of what you want to achieve. That's simple; reverse the loop that does the drawing.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I have Cisco PBX outputing date in NTP format like this:
09:47:55.999 BAH Sun Dec 7 2014
10:06:58.245 BAH Sun Dec 7 2014
11:21:18.723 BAH Sun Dec 7 2014
I want to know how can I convert it to UTC format in order to save it to MySQL database datetime field?
Thanks,
Jassim
Technology News @ www.JassimRahma.com
|
|
|
|
|
|
Assuming the format you want is ISO 8601 [^]:
09:47:55.999 BAH Sun Dec 7 2014
Should be transformed into: YYYY-MM-DDThh:mm:ss.sTZD
2014-12-07T09:47:55.999+03:00
?
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Sir,I want use datagridview with tab control.plz send me link where i can understand,how can i use tabcontrol with datagridview.
thanks
|
|
|
|
|
Hi,
Check my Article which is realted to adding controls to Datagridview.You can use the same functionality add tab control
DataGridView Helper Class[^]
|
|
|
|
|
Hi guys!
When i create my project, i want to display a single page in a c# WinForms, same as a website, when i click on an item of navibar, other page will display. I have already tried to search but i can't find out.
Like this <a href="http://paulstovell.com/blog/wpf-navigation"></a>
Can you point me control or library extended in c# to do that, not MDI form?
Thanks!
|
|
|
|
|
Where are your 'pages' coming from and how are you switching between them?
|
|
|
|
|
|
Presumably, by calling some methods, or setting some properties in the tab control. Your question is far from clear.
|
|
|
|
|
Hello Everyone,
I have run into a coding problem that has been driving me crazy for two days. I am running a console project from within my C# project using Process.Start() and trying to read the output into a string in my project. I have tried everything that I have found on the internet over the last two days and nothing works. Always returning an empty string. I have tried both synchronous and asynchronous methods and everything in between ie reading standarderror as well as standoutput. The exe that is being called is codegen.exe which is the compiled binary for creating a song fingerprint in Echoprint.
I can run this from a code prompt and it works perfectly every time outputting a fingerprint string. I am running windows 7 / VS2013 Express. The funny thing is, I have the source code for the codegen.exe and the data being output to the console is using nothing other than printf statements so there is nothing surprising going on there.
I did try doing a simple call to cmd.exe with "dir" argument and it responds correctly and fills my string with its output.
I am hoping that someone can suggest something that I have not yet tried, however I have tried all the different examples from MSDN as well as the internet.
Perhaps some one has had a similar issue and can offer some suggestions or point me in a different direction.
Any help would be appreciated.
Ray H
modified 8-Dec-14 11:21am.
|
|
|
|
|
I have never used EchoPrint, or launched a Console Application using Process.Start from within a WinForms project, so what follows may be irrelevant, or useless, but, given the fact you've done thorough searching, and haven't come up with anything, and on the odd chance it may be helpful, I'll put it out here.
If I find out this is not relevant, I'll remove this message, and my "feelings" will not be "hurt"
Is it possible that if you launch a Console from a C# project using the 'AllocConsole API, you can then, somehow, get that Console running codegen.exe ... so you would, then, be able to interact ?
Your C# project is WinForms, or WPF, or C++ ?
The 'AllocConsole API works for me (only tested in .NET 4.5) to enable two-way interaction between a Win Form and a Console it launches:
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
private static extern bool AllocConsole();
private void button1_Click(object sender, EventArgs e)
{
AllocConsole();
MessageBox.Show(ConsoleWriteAndReadLine(new string[]{"arg 1","arg 2","arg 3"}));
}
private string ConsoleWriteAndReadLine(string[] values)
{
Console.WriteLine("Command line = {0}", Environment.CommandLine);
for (int i = 0; i < values.Length; i++)
{
Console.WriteLine("argument{0} = {1}", i + 1, values[i]);
}
Console.Write("? ");
return Console.ReadLine();
} Perhaps the techniques shown in this CodeProject article would be helpful: [^] ?
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Thanks Bill,
The project is a WinForms project and this is a code snippet from MSDN on how to do exactly what I want to do. But it never works.
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Write500Lines.exe";
p.Start();
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
|
|
|
|
|
This is the latest iteration that I tried which I found on the web.
using (var process = new Process())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.FileName = "Codegen.exe";
process.StartInfo.Arguments = open.FileName + " 10 30";
process.Start();
//Thread.Sleep(100);
using (Task processWaiter = Task.Factory.StartNew(() => process.WaitForExit()))
using (Task<string> outputReader = Task.Factory.StartNew(() => process.StandardOutput.ReadToEnd()))
using (Task<string> errorReader = Task.Factory.StartNew(() => process.StandardError.ReadToEnd()))
{
Task.WaitAll(processWaiter, outputReader, errorReader);
standardOutput = outputReader.Result;
standardError = errorReader.Result;
}
|
|
|
|
|
Wish I could be more helpful, Ray, but you're traveling in terra incognita for me. I was surprised I could get two-way interaction working starting-up the Console with 'AllocConsole.
Hopefully, one our deeply knowledgeable wizards will show up, soon, with the right incantations.
cheers, Bill
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
May be something like this will help:
StringBuilder returnValue = new StringBuilder();
Process P = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "Codegen.exe";
p.StartInfo.Arguments = open.FileName + " 10 30";
p.Start();
p.OutputDataReceived += (o, e) =>
{
if (e.Data != null)
returnValue.AppendLine(e.Data);
};
p.ErrorDataReceived += (o, e) =>
{
if (e.Data != null)
returnValue.AppendLine(e.Data);
};
p.Start();
p.BeginOutputReadLine();
p.BeginErrorReadLine();
p.WaitForExit();
p.Close();
p.Dispose();
if (returnValue.Length > 0)
{
standardOutput = returnValue.ToString();
}
|
|
|
|
|
Harsh, thanks so much as this now works. I cant explain the difference between
p.OutputDataReceived += (o, e) =>
{
if (e.Data != null)
returnValue.AppendLine(e.Data);
};
and what I tried before which was using a separate handler assigned to OutputDataReceived.
Is your code different from
sortProcess.OutputDataReceived += new DataReceivedEventHandler(SortOutputHandler);
private static void SortOutputHandler(object sendingProcess,
DataReceivedEventArgs outLine)
{
}
However your code works so thanks very much
Regards
Ray
|
|
|
|
|
I am glad that it worked for you.
Basically your code and mine is almost same. While your code is creating explicitly named event handler, mine creates anonymous function.
I think the difference is that I am capturing the stdErr output to the string variable as well.
|
|
|
|
|
i want to show the selected cheakbok values from one grid view to another grid view in windows form.
|
|
|
|
|
Fine, that is what you want to do, but you will need to explain in more detail why you cannot do it.
|
|
|
|
|