|
Hello Gurus,
How can I color a DataGrid row (or a certain cell) with any colors at will, not just "Alternting Color"?
Thanks with a $ billion!
Khang Nguyen
|
|
|
|
|
|
Dear Guru Jay, thanks so much for the tip. Let me look at it and try it out with my project & let you know. Probably, it will take me some time. -Khang-
|
|
|
|
|
Guru Jay,
It seems working out for me. Thanks so much!!!
|
|
|
|
|
It should be simple right? Is it possible to add a class file to my project without it copying locally to my project? I just want to "include" it from a specific location. Maybe I am adding the file to my project the wrong way...
|
|
|
|
|
Okay i'm an iditot
Anyway when you select "Add exsisting item" if you hit the little arrow on the "Open" button you can select "Link" which will include it from another location.
It took me a while to find that so I am explaing it here incase someone uses search
|
|
|
|
|
Kluch wrote:
It took me a while to find that so I am explaining it here in case someone uses search
Excellent policy! Its always nice to find answers along with questions when searching. What's really annoying is the "I finally figured it out." follow-up, without the answer.
Matt Gerrans
|
|
|
|
|
Any suggestions on tools for monitoring the current state of the CLR while running an app? For example, I'd like to know how many instances there are of a particular class and how many are eligible for collection, etc.
Alterntatively, (or additionally, it would be a handy enhancement to the log files) I'd appreciate any suggested starting points for namespaces to look into for getting this kind of information to do it myself. I had a quick look at System.Diagnostics , System.Threading , Microsoft.Win32 and a few others, but nothing jumped out at me.
Matt Gerrans
|
|
|
|
|
|
Thanks, I gave it a whirl. Pretty nifty graphs. Good thing I have a lot of memory!
Matt Gerrans
|
|
|
|
|
|
I have a piece of code which runs in another thread (not the UI thread).
//
listBox1.Items.Add(s);
//
But because listBox1 was created in another thread, VS2005 does not allow me to do this. I have been told that I need to use BeginInvoke or Invoke on the control to add the item.
Does anyone have any ideas on how I would code that? I need to pass a string which will hold the new string to add listBox1.
Thanks in advance.
John Young
Yippee Kai Yai
Signed Polomint.......
|
|
|
|
|
Something like this should do it:
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;
class test : System.Windows.Forms.Form
{
public delegate void Add(string s);
public ListBox box;
public Button button;
public test()
{
InitializeComponents();
}
public void InitializeComponents()
{
box = new ListBox();
button = new Button();
button.Location = new Point(70, 120);
button.Text = "Click Me";
button.Click += new EventHandler(button_Click);
this.Controls.Add(box);
this.Controls.Add(button);
}
private void StringAdder(string s)
{
box.Items.Add(s);
}
private void button_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(StartThread));
t.Start();
}
private void StartThread()
{
Add a = new Add(StringAdder);
for(int i = 0; i < 100000; i++)
{
IAsyncResult ar = a.BeginInvoke("Nick", null, null);
}
}
[STAThread]
public static void Main()
{
Application.Run(new test());
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
No, that will end up on a thread-pool worker thread. You need to use Control.Invoke (or BeginInvoke) to get back onto the user-interface thread. Control is a placeholder: it's an instance member, so you need to supply a Control or a class derived from Control on the left of .Invoke.
The fact that your code sometimes works in .NET 1.x is an accident. There's always a possibility of race conditions or deadlocks. Some controls work, others don't.
Typically you'd Invoke on the form itself, e.g.:
private void StartThread()
{
Add a = new Add(StringAdder);
object[] args = new object[] { "Mike" };
for(int i = 0; i < 100000; i++)
{
this.Invoke( a, args );
}
} (shamelessly stealing Nick's example).
You'd BeginInvoke rather than Invoke if you wanted the UI notification to happen asynchronously. Invoke waits for the UI thread to finish processing the call before continuing. Some sources suggest always using BeginInvoke since you can't know how busy the UI is going to be, and you can end up deadlocking in some situations. This is the equivalent of using PostMessage versus SendMessage in C++ code.
Windows Forms 2.0 enforces the correct model: it always throws if you try to update UI from the wrong thread.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Ok, I understand what you are both saying. Would this work? Also the line
Add a = new Add(StringAdder);
has me confused. What is add? The compiler complains about me missing a Using directive.
string s;<br />
s = "Timeout";<br />
Add a = new Add(StringAdder);<br />
IAsyncResult ar = a.BeginInvoke(s, null, null);<br />
Thanks again.
PS: What about things like listBox1.Items.Clear() etc...
Yippee Kai Yai
Signed Polomint.......
|
|
|
|
|
polomint wrote:
What is add?
Add was defined as a delegate . You can read more about it here[^]. If you noticed, the StringAdder method I wrote matched the method signature defined in the Add delegate . It basically allows me to treat StringAdder as a callback function when the BeginInvoke method is called from another thread.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Damn, I should have read the code properly. I never noticed the delegate. I've always been impatient.
Thanks again..
Yippee Kai Yai
Signed Polomint.......
|
|
|
|
|
Mike Dimmick wrote:
Invoke waits for the UI thread to finish processing the call before continuing
In my test example, I didn't want to wait, which is why I went with the asynchronous call.
Mike Dimmick wrote:
Windows Forms 2.0 enforces the correct model: it always throws if you try to update UI from the wrong thread.
Hmm, I will have to check this out at home, I don't have Visual Studio 2005 here at work.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Yep, your right, I can do it in .NET 1.1 but 2.0 doesn't like it. In fact, Visual Studio shows this error:
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi all,
1) For one of the columns in my datagrid, I want the header text to be "Hourly Rate". I want "Hourly" displayed on top with "Rate" underneath it. How can I do this in C#?
2) How can I align the header text of a column to be center while the data is aligned as left?
I can align the entire column (affecting both Data and header) only.
Please help
THanks.........
|
|
|
|
|
First of all, I'm using the .NET COMPACT Framework. I have a message box, with yes and no buttons. When a user clicks yes, a large amount of logic is executed (databases are queried, xml is parsed, docs are printed, etc). All of this logic takes about 10 seconds to complete, but the confirmation dialog just hangs there with the yes button depressed until a "success" message box is displayed. My boss doesn't like the way this looks, because the program appears to be "frozen". I would like to have the confirmation box disappear after the user presses yes - is this only possible if i bring up something else (i.e. a progress bar)? Also, is it possible to have a progress bar in a messagebox?
Here is the code I'm using for the confirmation box:
if(MessageBox.Show("Backflush Pallet "+pallet+"?","Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
{
...execute tons of logic...
}
Thanks,
j1e1g1
|
|
|
|
|
Hmm...this is slightly tricky since that dialog isn't controled by you and therefore can't do self contained logic on how to appear/disappear. I'm not familiar with how the Compact Framework behaves but it might be solved if you let the message pump work. What might be going on is that the message "close dialog" is in the message queue but isn't being done because of the "execute tons of logic" bit.
I'm not sure how long of a fishing excirse you want to go on but one thing you can try is putting the "execute tons of logic" in another thread and let the message pump work in the primary UI thread. I'm not sure if this will work because as I said I am not sure how the Compact Framework behaves with threaded behavior let alone how the UI functions in subtle behaviors like this.
|
|
|
|
|
Wack in a call do Application.DoEvents() just before the "tons of logic" and the message box will disappear.
|
|
|
|
|
The simplest method would be to break the
MessageBox.Show call out of the if block.
DialogResult dr;
dr = MessageBox.Show(yadda, yadda)
if(dr == whatever) {
.. do tons of whatever stuff
}
|
|
|
|
|
HI~
I use a listview(large icon) of compact framework. After I click a item, it launches to another form with large icon listview.
However, after I launch to another form, all the icons of the previous form in the were disappeared.
How can I solve it?
Thanks
|
|
|
|