|
Try comparing your code to this: I know it works, I just tried it!
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Testy
{
public partial class frmTest : Form
{
public frmTest()
{
InitializeComponent();
}
private void butFillIt_Click(object sender, EventArgs e)
{
try
{
if (dgvDisplay.ColumnCount == 0)
{
string[] strNames = { "MyColumn", "More", "3", "4", "5", "6" };
int iBase = 1;
foreach (string s in strNames)
{
dgvDisplay.Columns.Add("Base" + iBase, strNames[iBase - 1]);
iBase++;
}
}
string[] sa = { "Hello", "there", "this", "is", "a", "test" };
for (int i = 0; i < 5; i++)
{
sa[0] = "Hello " + i;
dgvDisplay.Rows.Add(sa);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void butDoIt_Click(object sender, EventArgs e)
{
try
{
List<DataGridViewRow> list = new List<DataGridViewRow>();
foreach (DataGridViewRow dr in dgvDisplay.Rows)
{
if ((dr.Cells.Count > 0) && (dr.Cells[0].Value != null))
{
list.Add(dr);
}
}
butUndoIt.Tag = list;
dgvDisplay.Rows.Clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void butUndoIt_Click(object sender, EventArgs e)
{
try
{
Button currentButton = sender as Button;
List<DataGridViewRow> list = currentButton.Tag as List<DataGridViewRow>;
if (list != null)
{
foreach (DataGridViewRow dgvr in list)
{
dgvDisplay.Rows.Add(dgvr);
}
currentButton.Tag = null;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Works GREAT Thank YOU very much! u made my day
|
|
|
|
|
<Hi all,
i have the following generic classes that allow me to build up a command list. But I am struggling with the implementation of the IEnumerable GetEnumerator . I do not know how to implement it so that it returns the results?
Here is my code:
class Command<K, T>
{
public K Key;
public T Item;
public Command<K, T> NextCmd;
public Command()
{
Key = default(K);
Item = default(T);
NextCmd = null;
}
public Command(K key, T item, Command<K, T> nextNode)
{
Key = key;
Item = item;
NextCmd = nextNode;
}
}
public class ServerCommand<K, T> : IEnumerable<T> where K : IComparable<K>
{
private Command<K, T> tempCmd;
private T Find(K commandKey)
{
Command<K, T> current = this.tempCmd.NextCmd;
while (current.NextCmd != null)
{
if (current.Key.CompareTo(commandKey) == 0)
break;
else
current = current.NextCmd;
}
return current.Item;
}
public T this[K commandKey]
{
get { return this.Find(commandKey); }
}
public ServerCommand()
{
tempCmd = new Command<K, T>();
}
public void AddCommand(K commandKey, T commandItem)
{
Command<K, T> newCmd = new Command<K, T>(commandKey, commandItem, this.tempCmd.NextCmd);
this.tempCmd.NextCmd = newCmd;
}
public IEnumerator<T> GetEnumerator()
{
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
Many thanks in advance.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
You want to iterate all the child nodes starting from tempCmd right?
public IEnumerator<T> GetEnumerator()
{
Command<K, T> command = this.tempCmd;
do{
yield return command.Item;
command = command.NextCmd;
}
while(command != null);
}
|
|
|
|
|
Thanks!!
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
You're going to have to write a class that implements IEnumerator<T>. Then just return an instance of that class. It would just be a small class that captures some state: the first node ( for Reset ) and the current node ( for Current & MoveNext ).
Or you can write an iterator with the yield keyword, which basically gets the compiler to write the class for you.
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
Thanks for the response and the info Nick.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Hallo!
What is the problem?
I have the Server and Client form here http://board.gulli.com/thread/141481...t-fhig-machen/[^]
So it works the fully code, i can open Word,Ecxel and shutdown in x sec.
f (get == "rWord")<br />
System.Diagnostics.Process.Start("winword");<br />
if (get == "rExcel")<br />
System.Diagnostics.Process.Start("excel");<br />
string[] get_Split = get.Split('~');<br />
int time = Convert.ToInt32(get_Split[1]);<br />
if (get.Contains("rshutdown"))<br />
{<br />
System.Diagnostics.Process.Start("shutdown", "-s -t " + time.ToString());<br />
}<br />
}
And so it do nothing!
string[] get_Split = get.Split('~');<br />
int time = Convert.ToInt32(get_Split[1]);<br />
if (get.Contains("rshutdown"))<br />
{<br />
System.Diagnostics.Process.Start("shutdown", "-s -t " + time.ToString());<br />
}<br />
}<br />
if (get == "rWord")<br />
System.Diagnostics.Process.Start("winword");<br />
if (get == "rExcel")<br />
System.Diagnostics.Process.Start("excel");
|
|
|
|
|
|
OK Sorry
The first code i have posted works!
And the Second is the same but the Array is in the end!This code doesn´t work!
|
|
|
|
|
are you getting any error... because in your sample the first method and the second method both are same... the only difference is the ifstatement goes last and the arrar comes first...
|
|
|
|
|
you getting a compiler error? or runtime?
what about the second '}'? is that in the wrong place? hard to tell without the opening code
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Do you have an example value for "get" ?
Also System.Diagnostics.Process.Start("shutdown", "-s -t " + time.ToString()); will shut the machine down if called, not Word or Excel.
|
|
|
|
|
It´s difficut to explain it!
I have a Server and a Client. the Client have many Buttons for examble open Word , shutdown,...
When i use this code in the Server i can click on open Word or shutdown both works!
if (get == "rWord")<br />
System.Diagnostics.Process.Start("winword");<br />
if (get == "rExcel")<br />
System.Diagnostics.Process.Start("excel");<br />
string[] get_Split = get.Split('~');<br />
int time = Convert.ToInt32(get_Split[1]);<br />
if (get.Contains("rshutdown"))<br />
{<br />
System.Diagnostics.Process.Start("shutdown", "-s -t " + time.ToString());<br />
}<br />
}
When i use this code where the sring[] is on the front place i can´t open word! but i can shutdown the Pc in x sec!?
<br />
string[] get_Split = get.Split('~');<br />
int time = Convert.ToInt32(get_Split[1]);<br />
if (get.Contains("rshutdown"))<br />
{<br />
System.Diagnostics.Process.Start("shutdown", "-s -t " + time.ToString());<br />
}<br />
}<br />
if (get == "rWord")<br />
System.Diagnostics.Process.Start("winword");<br />
if (get == "rExcel")<br />
System.Diagnostics.Process.Start("excel");
Why is that so that only the one command work?
|
|
|
|
|
PC17 wrote: It´s difficut to explain it!
I can't imagine why it would be difficult. Just give us the facts, with all the relevant details, and you'll get an answer. Read my sig.
Here are just a few of the unclear points:
- are client and server on the same machine? if not:
- where is winword or excel to run? how is the client involved?
- which machine should shutdown? the server? can any client tell the server to shutdown?
And you should publish code inside PRE tags, that way you would have seen yourself that at least one of your code snippets will not even compile. Read my sig.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Aha! Now I understand. The problem is with these lines
string[] get_Split = get.Split('~');
int time = Convert.ToInt32(get_Split[1]);
Take the example of starting word. get is "rWord" get_Split will have length 1
ie:
get_Split[0] = "rWord"
the line
int time = Convert.ToInt32(get_Split[1]);
tries to access an array element that doesn't exist get_Split[1] , this will throw an error.
This will work
if (get == "rWord")
System.Diagnostics.Process.Start("winword");
if (get == "rExcel")
System.Diagnostics.Process.Start("excel");
if (get.Contains("rshutdown"))
{
string[] get_Split = get.Split('~');
int time = Convert.ToInt32(get_Split[1]);
System.Diagnostics.Process.Start("shutdown", "-s -t " + time.ToString());
}
|
|
|
|
|
The two pieces of code aren't actually the same. You haven't just moved the string[] array, you've also moved the second } . Try this to see if it has any effect:
string[] get_Split = get.Split('~');
int time = Convert.ToInt32(get_Split[1]);
if (get.Contains("rshutdown"))
{
System.Diagnostics.Process.Start("shutdown", "-s -t " + time.ToString());
}
if (get == "rWord")
System.Diagnostics.Process.Start("winword");
if (get == "rExcel")
System.Diagnostics.Process.Start("excel");
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
@keefb
Thank you, you have understand my problem!
now i can open Word and so when i put the code on the Front place!
But now this code doesn´t work!
if (get == "rshutdown_without_warning")
System.Diagnostics.Process.Start("shutdown", "-s -t 0");
if (get == "rshutdown_abort")
System.Diagnostics.Process.Start("shutdown", "-a");
thank you at all!!!
EDIT:
I don´t know why but it works!
Thank you at everybody, it´s a very good forum, there are a lot of very clever people!
modified on Thursday, August 20, 2009 4:22 PM
|
|
|
|
|
hi everyone.
i am looking for some help with my project.
i have x and y position and a string. i want to write that string in a text document at that x and y position.
can anyone pls help me
|
|
|
|
|
Does x and y represent a character index and a row index?
If you want to edit a text document then you need to read it, edit it, and write it to another file (temp) and then rename that file (with a File.Move) - unless you want to read all the file into memory then write it straight back to the original file, depends on file size really but I would avoid either way.
So you could use a System.IO.StreamReader to read the file a line at a time and write each one to temp file. Then when you get to the line you want to edit, add the data at the required position and write that line ti temp file. Then write remaining lines.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Here is one method:
1. Open a StreamReader
2. Open a StreamWriter to the new file
3. Do a ReadLine on the StreamReader y times, writing the result to the StreamWriter using WriteLine
4. On the Stream Reader Do a ReadBlock(x) and call Write on the StreamWriter, passing in the result.
5. Write the text to be inserted
6. Call StreamReader.ReadToEnd() and write the results to file using the Writer.
There are a couple of things to look out for:
a) The algorith I have given you writes to the correct position. There could be out-by-one errors (e.g. writing to a character or line before of after the one desired) as I haven't tested it.
b) You'll get exceptions if y is greater than the length of the file. Similarly, if x is greater than the length of line y, an exception will be thrown
Take a look at http://msdn.microsoft.com/en-us/library/system.io.filestream.aspx[^], the "HowTos" at the bottom contain "How to Read from File" and "How to Write to File" links which will be useful.
|
|
|
|
|
thank u.....
actually i have to create a new file and write the text at a particular X and y position.
how do i do that?
i have the position X and Y in pixels.
|
|
|
|
|
That's even easier. Open the StreamWriter and loop around y times calling WriteLine("") each time.
Next loop around x times calling Write(' ') assuming you want to use space as your padding character.
Call Write again, passing in the text you want to insert.
Again, you'll need to check the output file to esure the method I have given you is correct as I haven't checked it and it might all be out by one line and/or character.
|
|
|
|
|
|
That doesn't make any sense. Text holds characters and doesn't know about fonts and sizes, so pixels don't exist in the world of text.
Formatted text (such as a Word document, a Wordpad document, an HTML document) knows about formatting, but strictly speaking still does not know about exact pixel location.
If it is formatted text you're after, first thing to decide is which format to use.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|