|
There are various books out there on the subject already. Our policy was just to use the standards in the book - it saved us a lot of time writing standards.
|
|
|
|
|
Colin Angus Mackay wrote: Our policy was just to use the standards in the book - it saved us a lot of time writing standards.
Very much true. It saves a lot of time and effort.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
A pessimist sees only the dark side of the clouds, and mopes; a philosopher sees both sides, and shrugs; an optimist doesn't see the clouds at all - he's walking on them. --Leonard Louis Levinson
|
|
|
|
|
|
|
Hello all. I need some assistance. If I have a form that has buttons (or any Control(s)) on it, and I want to be able to populate a datagridview at runtime by selecting the control name from a combobox, how do you call the GetValue(object, object[] index) method on it to get the value of the property. I have no problem getting the list of property names, but I cannot get the values!
This code works. All but the GetValue method. I keep getting a 'TargetException: Object does not match target type' error.
Please give me a code example of how to properly call this GetValue(object, object[] index) method.
Once again,
The method that updates the gridview(right now it is a textbox in this code; I will change it later) and the class that handles the properties:
private void myCboBox_SelectedIndexChanged(object sender, EventArgs e)
{
MyProperty Myproperty = new MyProperty(null, null);
//creates an int to hold the selected index:
int index = myCboBox.SelectedIndex;
//creates a type variable:
Type t = controls[index].GetType();
PropertyInfo[] myProps = t.GetProperties();
foreach (PropertyInfo p in myProps)
{
richTextBox1.Text += "\n" +
//This GetValue(object, object[] index)
//is what I need to know how to do:
p.Name + "\t\t\t\t" + p.GetValue(Myproperty, null);
}
}
}
public class MyProperty
{
public MyProperty(string aName, object aValue)
{
theName = aName;
theValue = aValue;
}
private string theName;
public string theNameProp
{
get { return theName; }
set { theName = value; }
}
private object theValue;
public object intTest2
{
get { return theValue; }
set { theValue = value; }
}
}
"If you don't know where you're going, you'll probably end up somewhere else." Yogi Berra
|
|
|
|
|
When using GetValue , you must pass an object of the same type that you used to create the PropertyInfo object.
So this should work:
p.GetValue(controls[index], null);
Then you can fill the MyProperty object if you need to.
|
|
|
|
|
Hi,
I am trying to read log files that are updated by a daemon process on the server. The daemon process is an COM application writing to the files exclusively. How can I read the files? To simulate the workflow, I have created the following snippet, which reproduces the problem I am facing.
I get the exception : "The process cannot access the file 'C:\\Temp\\FileLockTest1.txt' because it is being used by another process."
static void Main(string[] args)
{
FileStream exclusiveWriter = new FileStream(@"C:\Temp\FileLockTest1.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
for (byte counter = 0; counter < 100; counter++)
{
exclusiveWriter.WriteByte(counter);
}
FileStream sharedReader = new FileStream(@"C:\Temp\FileLockTest1.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
sharedReader.Seek(0, SeekOrigin.Begin);
for (byte counter = 0; counter < 100; counter++)
{
Console.WriteLine(sharedReader.ReadByte());
}
exclusiveWriter.Close();
sharedReader.Close();
Console.ReadLine();
}
Thanks in advance,
- Johnson
|
|
|
|
|
JohnsonDesouza wrote: "The process cannot access the file 'C:\\Temp\\FileLockTest1.txt' because it is being used by another process."
This is because the file is opened by "exclusiveWriter" object and has not closed yet. You need to close it before opening the file for reading.
FileStream exclusiveWriter = new FileStream(@"C:\Temp\FileLockTest1.txt", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
for (byte counter = 0; counter < 100; counter++)
{
exclusiveWriter.WriteByte(counter);
}
exclusiveWriter.Close();
FileStream sharedReader = new FileStream(@"C:\Temp\FileLockTest1.txt", FileMode.Open, FileAccess.Read, FileShare.Read);
sharedReader.Seek(0, SeekOrigin.Begin);
for (byte counter = 0; counter < 100; counter++)
{
Console.WriteLine(sharedReader.ReadByte());
}
sharedReader.Close();
Console.ReadLine(); You can also consider to use using block.
|
|
|
|
|
JohnsonDesouza wrote: How can I read the files?
To be clear here - you cannot. That's what exclusive lock means. Someone has shown how to remove the lock in C#, if this is a COM C++ program, you need to change that code to close the file.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
yes you can read log files from ongoing processes provided they are coded appropriately.
you'll have to change the code: by default a file writer opens the file denying the world to
see the file's content for as long as it is open. IMO you have three options:
1.
have the writer close the file when done; from then on any app can read the file.
2.
have the writer perform open-for-append, append, close for every write it wants to execute.
that way readers will succeed most of the time. This is my way of implementing logging.
It is not great performance wise, but it works great.
3.
have the writer open the file with FileShare.Read i.e. have it allow others to read while
the writer has the file open. There are two caveats:
a) there is some buffering going on, so the writer should perform the right Flush() operation
to force the data out, making it available for the reader(s).
b) the file may be in an intermittent state (not fully consistent) when the reader gets data
at the same time the writer is adding to it. So readers should be tolerant.
|
|
|
|
|
Hi Everyone,
I have a statusstrip control on my form and how do I show some text on it. I tried the text property but nothing is visible on the form. kindly help. I know this question may sound silly to some but then I am just a beginner
Regards,
LG
lgatcodeproject
|
|
|
|
|
Hi,
The status strip is a sort of menu / toobar. You have to add something to it,
like a ToolStripStatusLabel, and then assign your text to that label.Text.
In the forms designer, if you left click on the statusStrip (in the form),
you should see a little box with an arrow. Left click on that, and you get
a menu of items you can add (label, progressBar, dropDownButton,
splitButton). Click on one to get the item added.
Then go to the properties of the item you added and assign the name. I hope this would be helpful.
Regards,
Vinay
ComponentOne LLC.
www.componentone.com
|
|
|
|
|
Hello Vinay,
Thanks, it solved my purpose. Can we configure some other items (other than those provided in the dropdown)to this status strip in runtime?
Regars,
LG.
lgatcodeproject
|
|
|
|
|
One of my articles might be able to help you their: Custom ToolStrip Renderers[^]. You are able to add other controls using the ToolStripControlHost. You can browse most of the classes that can manipulate the ToolStrips by using the Object Browser.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
I am trying to add propertyitem dynamically to property grid.
For example If I want to add a property Item Like a text box which takes "String name" as variable how to add dynamically to property Grid?
I can do the following to add the "name" text box at static design time:
public class PropertyGridProcessDesigner
{
[Editor(typeof(PropertyGridProcessDesigner), typeof(System.Drawing.Design.UITypeEditor))]
public string Name
{
get { return name; }
set { name= value; }
}
}
But how to achieve the same above thing at run time ?
Do we need to create dynamic classes to add Property Item ?
If so, can anyone please share any information you have ?
Thanks,
rajan
|
|
|
|
|
|
// Save the stream to disk
System.IO.FileStream newFile = new System.IO.FileStream(Server.MapPath(sSavePath + sFilename), System.IO.FileMode.Create);
newFile.Write(myData, 0, myData.Length);
newFile.Close();
TextWriter tw = new StreamWriter(Server.MapPath("Images/Saved Images/info.txt"));
// write a line of text to the files
tw.WriteLine(txtFName.Text + " " + txtLName.Text + " " + IDTextBox.Text + " " + sSavePath + sFilename);
// close the stream
tw.Close();
it works but whenever i try to upload 2 or more files/images... it will just overwrite the exisiting texts.. how do i make it such that it will create a new line each time i upload an image upon the existing ones?
|
|
|
|
|
Do you mean you want to open an existing file and APPEND data to the end of it?
|
|
|
|
|
Thomas Toh wrote: System.IO.FileMode.Create);
This creates a new file, like it says. Use Append to add to an existing file.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
File.AppendText() seems to be the easiest way to get what you want.
|
|
|
|
|
Hi all,
Basically i have 2 question in this message.I am using DataGridViewComboBoxColumn to insert a ComboBox into my datagridview.Code as below:
dataGridView1.Columns.Remove("Seqence_Number"); <----remove the original column first before add the combo box
DataGridViewComboBoxColumn dgvComboBox = new DataGridViewComboBoxColumn();
dgvComboBox.DataPropertyName = "Seqence_Number";
dgvComboBox.HeaderText = "Sequence (Stage)";
dgvComboBox.DropDownWidth = 100;
dgvComboBox.Width = 100;
dgvComboBox.MaxDropDownItems = 10;
dgvComboBox.FlatStyle = FlatStyle.System;
dsTemp = singleton.ProdetailsDataset.Copy(); <-----dataset will copy from my singleton class
dgvComboBox.DataSource = dsTemp.Tables[0];
dgvComboBox.ValueMember = "Stage_Name";
dgvComboBox.DisplayMember = "Stage_Name";
dataGridView1.Columns.Insert(1,dgvComboBox);
The first question is, how can i display more than one value member in ComboBox?
The second qeustion is, how can i do a selected event for that ComboBox in datagridview? what i wanna do is when user select the value in ComboBox, some event will fire to validate the value which selected by user.
Any tips are welcome,
Thanks in advance
|
|
|
|
|
Hi,
1) Concatnate the two column values (in a query) and assign as a value member.
2) You can use "EditingControlShowing" event to access the "SelectedIndexChanged" event for combobox cell.
Here is the Code Snipet:
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.EditingControlShowing += new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(this.dataGridView1_EditingControlShowing);
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox ctl = e.Control as ComboBox;
if(ctl!=null)
ctl.SelectedIndexChanged+=new EventHandler(ctl_SelectedIndexChanged);
}
private void ctl_SelectedIndexChanged(object sender, EventArgs args)
{
MessageBox.Show("Selected Index Changed Event");
}
Thanks,
Gopal.S
|
|
|
|
|
Hi Gopal.S
Thanks for your suggestion. I am just figure out how to do it, but seem you have a better suggestion
1) I just simple Concatnate the columns after i get the dataset, something like below:
string s = dsTemp.Tables[0].Rows[1][2].ToString() + dsTemp.Tables[0].Rows[1][3].ToString();
2) I am using CellEndEdit ,as below;
this.dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
string cellvalue;
if (e.ColumnIndex == 1)
{
cellvalue = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
if (cellvalue != null && cellvalue != "")
{
}
}
I will try you suggestion too, Thanks 
|
|
|
|
|
Member Function Pointers usage on class instances:
Class A is derived from Class ZZZ. Class A has a member function A::ftnOnA
Class B is derived from Class YYY.
Class A instantiates Class B
Could Class A pass a member function pointer to Class B and then Class B be able to call A::ftnOnA? (Like a call back procedure)
Can anyone please help me?
|
|
|
|
|
You can set up a delegate to achieve this.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|