|
Invalidate will definately cause your form to repaint itself. Put a breakpoint on the invalidate call to see when it gets called, then when it's called, put one in your paint event and step through to see why your box is not being drawn as you expect.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
What's a breakpoint do? Simple question probably, but I'm new...
The most knowledge doesn't mean the most wise...
|
|
|
|
|
I JUST GOT IT TO WORK!! THANKS A LOT!!!;P
The most knowledge doesn't mean the most wise...
|
|
|
|
|
NP - sorry I didn't come back sooner, very busy day for me today.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
It's cool.
The most knowledge doesn't mean the most wise...
|
|
|
|
|
Hi to All,
This is my first aquaintance with the forum as I am new to this forum as well as C# also.
So the question may be foolish & yet it prevails.
Hope you understand me ..
Q: Is Application.Run() function always necessary to display your form? Can't we bypass it? I tried to do and my form instance was just flashing and exiting...
Thanks in anticipation..
Regards
-- modified at 3:25 Sunday 14th October, 2007
|
|
|
|
|
I'm almost 100% sure, that it is necessary.
Your application needs to be executed somewhere in the code.
Virtual1ty "Any fool can learn from his own mistakes, but a wise man learns from mistakes of others"
|
|
|
|
|
Hi,
to have a live Windows app, showing Windows and reacting to the user, you need
a "message pump", i.e. an event queue that collects GUI events, and a loop that reads
from that queue and executes the messages. The normal way to achieve this is by
calling Application.Run(); there may be other ways to achieve the same, but nothing
as simple as the one line that does everything that is required.
BTW: you don't need Application.Run() when you don't need the message pump, as in
a Console app.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Question - why do you think it's there, if it's not necessary ? Why do you want to bypass it ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks to all ...
Really..
So now I get that the message pump that is required is provided by Application.Run(). Otherwise the application would die without any messages..
Thanks once again folks.
|
|
|
|
|
dear all,
I need a way to query a dns for example "ns1.whatever.com" ;
in order to get domain entrys on this NS ...
i need to do something like this site http://domainsdb.net/[^] but in windows application ...
thanks in advance for your co-operation
Davids Maguire
|
|
|
|
|
Check this[^] out.
Take care,
Tom
-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com
|
|
|
|
|
I'm going to break out my question into a smaller sub-question this time, instead of trying to fit two questions into one post.
I basically have a method Control.PerformOngoingOperation that can call other methods, with string IDs assigned to each calling. Its signature is, currently:
object PerformOngoingOperation(Delegate method, out string id, params object[] args)
However, as far as I can tell, the user then has to declare a delegate every time:
class C
{
delegate int annoying(int param1, bool param2, string param3);
void Method()
{
string id;
int retVal = (int)Control.PerformOngoingOperation(new annoying(Library.Object.Method), out id, 5, true, "test");
}
}
I suppose an alternative is requiring that the delegate be of type MethodInvoker (basically void return type, no parameters), as such:
string PerformOngoingOperation(MethodInvoker method)
and forcing the user to do this:
int retVal;
string id = Control.PerformOngoingOperation((MethodInvoker)(new delegate() { retVal = Library.Object.Method(5, true, "test"); }));
But that's awkward at best.
Ideally I would like to have something like this instead:
string id;
int retVal = Control.PerformOngoingOperation(Library.Object.Method, out id, 5, true, "test");
Is that possible? If so, what's the syntax?
-Domenic Denicola- [CPUA 0x1337]
“I was born human. But this was an accident of fate—a condition merely of time and place. I believe it's something we have the power to change…”
|
|
|
|
|
Domenic wrote: string PerformOngoingOperation(MethodInvoker method)
Something like that, yeah.
One thing to keep in mind is, the C# 2 compiler can infer the delegate type. So if you define it with a MethodInvoker (or a SendOrPostCallback, or any other delegate), the compiler can infer the delegate from usage. For instance, you can call it like this:
Control.PerformOngoingOperation(Lib.Obj.Method);
Notice how you didn't need to declare new MethodInvoker(Lib.Obj.Method) , the C# compiler inferred that Lib.Obj.Method has a signature matching MethodInvoker, so you don't have to explicitly create a new delegate instance there. Does that help?
The reason this doesn't work with Control.PerformOngoingOperation(Delegate del, ...) is because the compiler doesn't know which delegate to use with it, so it forces you to create a new delegate around the function you pass in.
|
|
|
|
|
Right, but since very few of my "ongoing operations" are void and parameterless, this is pretty useless. I'd instead create anonymous delegates (as shown above), which in fact do have to be cast to MethodInvoker
-Domenic Denicola- [CPUA 0x1337]
“I was born human. But this was an accident of fate—a condition merely of time and place. I believe it's something we have the power to change…”
|
|
|
|
|
You don't have to cast to MethodInvoker provided you specify an anonymous method that is parameterless and doesn't return anything. For example,
Control.PerformOngoingOperation(delegate()
{
Library.Object.Method(5, true, "test");
}
That will work just fine, no cast required.
It should be noted that in the .NET framework class libraries, it's a common practice to accept a method that returns void but takes 1 parameter of type object in order to pass in state.
For example, see ThreadPool.QueueUserWorkItem(SendOrPostCallback method, object state);
cc
Where SendOrPostCallback is a delegate that takes 1 object parameter.
Another thing you can do here is provide generic overloads for your Control.PerformOngoingOperation:
object PerformOngoingOperation(Function method, out string id)
</code><code>object PerformOngoingOperation<TArg>(Function<TArg> method, out string id, TArg arg)
</code><code>object PerformOngoingOperation<TArg1, TArg2>(Function<TArg1, TArg2> method, out string id, TArg1 firstArg, TArg2 secondArg)
</code><code>object PerformOngoingOperation<TArg1, TArg2>(Function<TArg1, TArg2, TArg3> method, out string id, </code><code>TArg1 firstArg, TArg2 secondArg</code><code>, TArg3 secondArg) And so on, as many as you like.
This way, your PerformOngoingOperation method can execute most any function without having to use the Delegate class; everything will be strongly typed and performance will be great as no late-bound method invocations will occur.
|
|
|
|
|
Hi ,
I am trying to read an MS Excel file in my C# class. But problem is its not showing me the column values. I have checked in actual excel file , those columns do contain values but due to some reason my code is not reading it.
here is what i m doing :
Code Blockstring filename = "xmp.xls;";
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source= " + filename + "Extended Properties=Excel 8.0;";
OleDbConnection ObjConn = new OleDbConnection(strConn);
ObjConn.Open();
object[] objArrRestrict;
objArrRestrict = new object[] {null, null, null, "TABLE"};
DataTable schemaTbl;
schemaTbl = ObjConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,objArrRestrict);
Hashtable ht = new Hashtable();
int index = 0;
foreach (DataRow row in schemaTbl.Rows)
{
ht.Add( index, row["TABLEX] );
index++;
}
string sheetName = (string)ht[0];
OleDbCommand ObjCmd = new OleDbCommand( "SELECT * FROM [" + sheetName + "]", ObjConn);
OleDbDataAdapter objDA = new OleDbDataAdapter();
objDA.SelectCommand = ObjCmd;
objDA.Fill(recordsDT);
ObjConn.Close();
DataRow rowx= recordsDT.Rows[14];
// and now if i try to read value of 6th column
rowx[5].ToString(); // gives empty string
rowx["6th Col"].ToString(); // it returns me empty string and actually this column do contain value
and similary i can't get values of col 7,8 but I do get the values of Col 1-5 and after Col 9.
But if I try to same column values of row 1,2 it works fine. It starts to get funny after row no 7. ( each row contains 80 coumns)
Thanks
ZINK
|
|
|
|
|
Hi would appreciate if you helped me with this strange problem.
i´m trying to write text from my listview into a excel file but the problem is that i want to change cells, now its writing in the same cell.
for example:
a1 a2 a3 a4
subitem[0] subitem[1] subitem[2] subitem[3]
subitem[0] subitem[1] subitem[2] subitem[3]
tryade this:
using (StreamWriter sw = new StreamWriter((path3 + namn), true))
{
for (int listIndex = 0; listIndex < this.listView2.Items.Count; listIndex++)
{
sw.WriteLine(this.listView2.Items[listIndex].Text + this.listView2.Items[listIndex].SubItems[1].Text + this.listView2.Items[listIndex].SubItems[2].Text + this.listView2.Items[listIndex].SubItems[3].Text);
}
Process.Start(namn);
enyone with a good knowledge with this problem???
TNX!!;)
|
|
|
|
|
The code you have provided makes no sense.
Nothing in your code explicitly refers to Excel.
You write some text to a StreamWriter but then don't do anything with it.
You call Process.Start with a variable that you haven't defined. What are you trying to do here?
When you say you are trying to create an Excel file, do you actually mean a delimited text file?
Paul Marfleet
|
|
|
|
|
no.. i just givin my example of what i thought..
this code writes in a .xls file but in one cell. I want to change cells foreach subitems..
how do i do that
appreciate this.
Big tnx!
|
|
|
|
|
You haven't posted all your code. There are a number of variables that are not defined.
Post all of your code. I can't help you unless I can understand what you are doing.
Paul Marfleet
|
|
|
|
|
ok..
my code to send info from my listview to a .xls file look like this:
string[] lines3 = System.IO.File.ReadAllLines("datainställningar.txt");
string path3 = lines3[0];
string text = textBox1.Text;
string namn = text + ".xls";
if (MessageBox.Show("Vill du skapa diagramet " + text + "?", "Mitt jobb",
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
using (StreamWriter sw = new StreamWriter(path3 + namn))
{
for (int listIndex = 0; listIndex < this.listView2.Items.Count; listIndex++)
{
sw.WriteLine(this.listView2.Items[listIndex].Text + this.listView2.Items[listIndex].SubItems[1].Text + this.listView2.Items[listIndex].SubItems[2].Text + this.listView2.Items[listIndex].SubItems[3].Text);
}
Process.Start(namn);
}
}
But now it´s writes in only a1 cells in .xls, but i want it to write every subitems in each cell.
is it more clearly now??
tnx
|
|
|
|
|
AFAIK, there are 2 ways to create an Excel file in .NET.
1. Excel Automation. Allows you to programmatically control the Excel application. Requies Excel to be installed on the machine your application is running on.
2. JET OLEDB Provider. Allows you to connect to an Excel spreadsheet like a database and read/write data to it. Doesn't require Excel to be installed, only the JET driver.
Google either of these and you should find numerous examples to get you started.
Paul Marfleet
|
|
|
|
|
Here is another method for generating Excel file from c# http://www.codeproject.com/dotnet/ExportToExcel.asp
|
|
|
|
|
This code will nevcer generate a REAL .xls file. You can generate a text .CSV (comma seperated values) file that Excel will import but it's not an .xls file.
|
|
|
|
|