|
I need write some values from an array in columns like below
for (int np=1; np < NP1 ;np++)
{
writer1.WriteLine ("{0,8},{1,8},{2,8},{3,8},{4,8},{5,8},{6,8},{7,8},
PARAM[1],PARAM[2],PARAM[3],PARAM[4],etc...
}
The problem is that the number of columns is calculated by the code
/it can varied/ . Second only a part of array should will be printed.
Regards
Ted
|
|
|
|
|
Can't you just nest another loop? Like:
int cols=3;
int testCount=PARAMS.length;
for (int rowIndex=0;rowIndex < Math.Ceiling (Convert.ToDouble (testCount) / Convert.ToDouble (cols));rowIndex++)
{
for (int colIndex=0;colIndex < cols;colIndex++)
{
if (rowIndex * cols +colIndex < testCount)
{
writer1.Write(PARAMS[rowIndex * cols +colIndex].ToString () + " ");
}
}
writer1.WriteLine();
}
That should write it one row at a time:
0 1 2
3 4 5
6 etc.
Hope this helps
Bill
|
|
|
|
|
My problem is now much more trivial:
how I can get my output as a row?, instead for column from example as below:
int []PARAM = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17};
int zmax =11;
for (int z = 0; z < zmax+1 ; z++)
writer1.WriteLine(PARAM[z].ToString()+ " ");
=== output
1
2
3
4
5
6
7
8
9
10
11
12
//Ted
teja
|
|
|
|
|
Oh! That is easier.
I do not know what writer1 is, since none of your previous posts contain a declaration...but in many cases there is a .Write() method as well as a .WriteLine. Is so you can do:
for (int i=0;i < PARAMS.Length; i++)
writer1.Write(PARAMS[i].ToString() + " ");
writer1.WriteLine()
If you have no Write, just build the string up before you print it.
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i=0;i < PARAMS.Length; i++){
SB.Append(PARAMS[i].ToString() );
SB.Append(" ");
}
writer1.WriteLine(SB.ToString())
|
|
|
|
|
I've got a small utility that occasionaly locks up in itself if a client does not respond, so I have added a time out clause by creating a side thread for it to run on, and killing the thread when the timeout condition is reached OR the thread completes.
However, creating an entirely new thread to run this on just seems daft, so i'd like to do it on a ThreadPool. Is there any way to kill a thread pulled from a thread pool after a certain amount of time?
Cheers
Cata
|
|
|
|
|
I solved a similar problem another way. I created a class to hold each thread's info. i.e. ThreadID,StartDateTime,InUse,Finished etc...
Then when a new thread is required I add an instance of this class to an array which is monitored from a single worker thread. In the worker thread I interate through the array of threads and kill the ones that have the Finished flag set or that have exceeded my timout based on StartDateTime, and InUse flags. That way you can handle the termination of each thread based on what type of operation it is.
Don't know if this is applicable to your solution or not, but it worked great for me.
|
|
|
|
|
My solution is very similar, but i use the ThreadState of the thread I create. THe thread is only active for at most 1200ms and on the median about 15ms, before it is terminated. Therefore, creating and disposing new threads is a waste.
I was looking for a way to use the thread pool as it would be a more appropriate solution.
|
|
|
|
|
Hello, please can anyone help. I need the article and source code for the C# Sorted ListView by Carlos H. Perez, as it is not at the following link anymore. I use a listview which continuously updates two of the subitems, which is causing bad flickering. I need to know how to update subitems on a listview, without redrawing the whole row.
http://www.codeproject.com/cs/miscctrl/sortedlistview.asp
If anyone has the sourcecode please can they send it me.
Kindest Regards
Mike
|
|
|
|
|
Hello, please can anyone help. I need the article and source code for the C# Sorted ListView by Carlos H. Perez, as it is not at the following link anymore. I use a listview which continuously updates two of the subitems, which is causing bad flickering. I need to know how to update subitems on a listview, without redrawing the whole row.
http://www.codeproject.com/cs/miscctrl/sortedlistview.asp
If anyone has the sourcecode please can they send it me.
Kindest Regards
Mike
|
|
|
|
|
Hi
I have done a c# program such that , it reads a xml schema and passes values
to the dataset and create a xml file appropriately for their datatypes
( for ex: john for string, 67 for int)
What I have to do is . At present it creates only 1 row (record) in the xml file.
should loop and create atleast 200 records. Also, think of ways where the 200 records
can be different from each other.
Here is the coding which i have done.
please help me to do my requirement
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Xml;
using System.Xml.Schema;
namespace testdatagenerator
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtSchema;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox txtXml;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Data.DataSet dataSet1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.txtSchema = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.txtXml = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.dataSet1 = new System.Data.DataSet();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
this.SuspendLayout();
//
// txtSchema
//
this.txtSchema.Location = new System.Drawing.Point(88, 24);
this.txtSchema.Name = "txtSchema";
this.txtSchema.Size = new System.Drawing.Size(440, 20);
this.txtSchema.TabIndex = 0;
this.txtSchema.Text = "";
//
// button1
//
this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button1.Location = new System.Drawing.Point(536, 24);
this.button1.Name = "button1";
this.button1.TabIndex = 1;
this.button1.Text = "Browse";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txtXml
//
this.txtXml.Location = new System.Drawing.Point(88, 64);
this.txtXml.Name = "txtXml";
this.txtXml.Size = new System.Drawing.Size(440, 20);
this.txtXml.TabIndex = 2;
this.txtXml.Text = "";
//
// button2
//
this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button2.Location = new System.Drawing.Point(536, 64);
this.button2.Name = "button2";
this.button2.TabIndex = 3;
this.button2.Text = "Load";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.button3.Location = new System.Drawing.Point(616, 64);
this.button3.Name = "button3";
this.button3.TabIndex = 4;
this.button3.Text = "Save";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.DataSource = this.dataSet1;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 120);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(776, 320);
this.dataGrid1.TabIndex = 5;
//
// dataSet1
//
this.dataSet1.DataSetName = "NewDataSet";
this.dataSet1.Locale = new System.Globalization.CultureInfo("en-US");
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(808, 454);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.txtXml);
this.Controls.Add(this.button1);
this.Controls.Add(this.txtSchema);
this.Name = "Form1";
this.Text = "TestDatagenerator";
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
OpenFileDialog fdlg = new OpenFileDialog();
fdlg.Title = "select schema file" ;
fdlg.InitialDirectory = @"c:\CDEV\testdatagenerator" ;
fdlg.Filter = "schema files(*.xsd) |*.xsd| all files(*.*) | *.*";
fdlg.FilterIndex = 2 ;
fdlg.RestoreDirectory = true ;
if(fdlg.ShowDialog() == DialogResult.OK)
{
txtSchema.Text = fdlg.FileName ;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
dataSet1.ReadXmlSchema(txtSchema.Text);
foreach (DataTable dTbl in dataSet1.Tables)
{
object[] oValues = new object[dTbl.Columns.Count];
int i = 0;
foreach (DataColumn dColmn in dTbl.Columns)
{
switch(dColmn.DataType.ToString())
{
case "System.String":
oValues[i] = (string) "This is string";
break;
case "System.Int32":
oValues[i] = (int) 100;
break;
case "System.DateTime":
oValues[i] = new DateTime(2004,10,12);
break;
case "System.Decimal":
oValues[i] = new Decimal(999999999.99);
break;
case "System.Int16":
oValues[i] = (short) 32767;
break;
case "System.Int64":
oValues[i] = (long) 9223372036854775807;
break;
case "System.Double":
oValues[i] = (double) 888888888888888;
break;
}
i += 1;
}
dTbl.Rows.Add(oValues);
}
}
private void button3_Click(object sender, System.EventArgs e)
{
dataSet1.WriteXml(txtXml.Text,XmlWriteMode.WriteSchema );
MessageBox.Show("Saved");
}
}
}
|
|
|
|
|
here is the problem let say that I 've the following DataGrid....
_______ ---------------------------------------------
Header _ ||col_01 || col_02 || col_03 || col_04 ||
_______ ---------------------------------------------
Row 0__ || __a__ || __b__ || __c__ || __d__ ||
_______ ---------------------------------------------
I NEED TO PAINT SO IT LOOKS LOKE THE FO::OWING
_______ -----------------------
Header _ ||col_01 || col_03 ||
_______ -----------------------
Header_ ||col_02 || col_04 ||
_______ -----------------------
Row 0__ || __a__ || __b__ ||
_______ -----------------------
Row 0__ || __c__ || __d__ ||
_______ -----------------------
I Hope The Idea Is now Clear ... so plz help me I need it yesterday............
|
|
|
|
|
hi
i want to check what key on keyboard is presed.
how kan i get the key pressed char code?
thanks
|
|
|
|
|
Create an event handler for the KeyDown, KeyPress or KeyDown event and evaluate the specific EventArgs object, that will be passed to the event handler.
www.troschuetz.de
|
|
|
|
|
If you are using a control (i.e. TextBox) you can use the KeyDown Event as follows:
private void ValueEdit_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
try
{
if(e.KeyCode == Keys.Enter)
CloseEditBox(true);
else if(e.KeyCode==Keys.Escape)
CloseEditBox(false);
}
catch(Exception Err)
{
throw new Exception("KeyDown: "+Err.Message);
}
}
if you want to trap the keyboard events for an entire application, you can override the WndProc method and look for the WM_KEYDOWN message
|
|
|
|
|
Dear all,
I cannot understand how to work with CJK in the PDF format.
Can anybody provide me a PDF file with Chinese or Japanese characters and
file description.
Any your help will be appreciated.
|
|
|
|
|
I am creating an instance of class at runtime from assembly through reflection.I then Serialize the class(including the delegates) and send it to remote machine from where I deserialize the received bytes.I can get an Exception i.e. its not deserialized in short!
However when I perform this whole mechanism without including Delegates... it works and the result is exactly what i want.
Can somebody help me on this ?
Thanks in Advance!
|
|
|
|
|
|
hey guys, i need to check a stirng if it contain the "ESC" character i searched for the representation of this char which was '\e' but when i write this char in the C# code it doesn't recognize it, does anyone knows how to do it?
|
|
|
|
|
What do you mean "when i write this char in the C# code"? How do you "write" it? The .NET Framework General Reference states that \e is the escape sequence for the ESC character, but it really matters what your "string" contains, how it's encoded, and how you're searching for the string. How are you searching the string? How is it encoded?
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
i ment simply writing a string whith this character as the following:
string strTest = "This is a Test\e string" ;
the '\e' character should represent an ESC but the compiler doesn't recognize this escape character, any way i found another way which is represnting the ESC as the follwoing:
string strTest = "This is a Test\u001B string" ;
the '\u001B' match the ESC char.
actully u can write the following:
char chTest = '\u001B' ;
which is totally legal.
|
|
|
|
|
Hello,
I am using the generic TreeView Control from .Net 2002.
I want to have the root nodes of the control to have a bold font and I thought this could be easily done by setting the NodeFont attribute of the node.
However, when I do this the font is indeed bold but it seems that the control does not resize the text box the node text is drawn in and the text gets clipped (I assume becase the new bold font is wider than the previously assigned text which isn't bold by default).
Does anybody know what I can do to fix this.
Sample of code below:
TreeView treeView = new TreeView();
...
TreeNode tn = new TreeNode("Test");
tn.NodeFont = new Font(treeView.Font, FontStyle.Bold);
...
Thank you in advance,
Eric
|
|
|
|
|
Simply add this line to ur code
TreeView treeView=new TreeView();
..
TreeNode tn = new TreeNode("Test");
System.Drawing.Font newFont=new System.Drawing.Font(treeView.Font, FontStyle);
tn.NodeFont = newFont;
treeView.Font = newFont;
...
//I hope u wud have understand the reason :P
Take Care
|
|
|
|
|
As I was afriad, the additional line of code (i.e. setting the treeView Font) just makes every node in treeView have the same font.
I only want the root nodes to be different!
Any other help; or maybe I didn't understand what you meant.
Eric
|
|
|
|
|
Alright !
TreeView treeView=new TreeView();
..
//-----Code For Adding the Root Node------
TreeNode tn = new TreeNode("Test");
System.Drawing.Font newFont=new System.Drawing.Font(treeView.Font, FontStyle.Bold);
tn.NodeFont = newFont;
treeView.Font = newFont;
...
//-----Code For Adding the Children Node------
TreeNode tn = new TreeNode("Test");
System.Drawing.Font newFont=new System.Drawing.Font(treeView.Font, FontStyle.Normal);
tn.NodeFont = newFont;
//OfCourse You add this Children to the Parent Node
//So add it to the Parent Node here but dont
//set or change the treeview Font.Only Set the Font of the Node
//OKAY ????
...
//The moral of the story is that u set the font of the treeview Ctrl
//to one that takes more graphical units (in value of course) for display text, so to avoid the clipping of text.Since displaying
//text in bold takes more graphical units as compared to same text in same
//normal font.So thats the reason u set the font treeview while adding the
//root node.
I hope u got the point
|
|
|
|
|
I see.
Seems like a funny way to have to set fonts for a node but I understand the reason why.
Thanks,
Eric
|
|
|
|
|