|
|
hey how to create dynamic gridview in default.aspx in page_load event
|
|
|
|
|
1. Add a placeholder on your ASP page (VERY IMPORTANT!).
2. Create a gridview from code, and add it to your placeholder's Control collection.
|
|
|
|
|
Hi,
I want to change a timer when I find that a particular process is running..
Here is my code:
class Program
{
System.Threading.Timer SendDataTimer;
static void Main(string[] args)
{
Program MyObj = new Program();
MyObj.MyMethod();
}
public void MyMethod()
{
TimerCallback tcb_SendData = new TimerCallback(Callback_Method_SendData);
SendDataTimer = new System.Threading.Timer(tcb_SendData, 0, 0, 1000);
Console.Read();
}
void Callback_Method_SendData(System.Object state)
{
Console.WriteLine("Timer Executed at: " + DateTime.Now.ToString());
foreach (Process p in Process.GetProcesses())
{
if(p.ProcessName == "notepad")
{
SendDataTimer.Change(0, 3000);
}
}
}
}
However in this, when I open notepad, the timer continues to run very quickly and when I close it, then it changes the timer..
Why is it so?
I want that the timer should change the timings as soon as notepad opens but does execute very fast when I open notepad and why dosent the time change in the interval when notepad is opened?
Why does it take to close the notepad and then the timer changes..
I hope you get my question.
Thanks.
|
|
|
|
|
ptr2void wrote: I want that the timer should change the timings as soon as notepad opens but does execute very fast when I open notepad and why dosent the time change in the interval when notepad is opened?
Why does it take to close the notepad and then the timer changes..
Let my copy the docs:
"period
The time interval between invocations of the callback method specified when the Timer was constructed, in milliseconds. Specify Infinite to disable periodic signaling.
dueTime
The amount of time to delay before the invoking the callback method specified when the Timer was constructed, in milliseconds. Specify Infinite to prevent the timer from restarting. Specify zero (0) to restart the timer immediately. "
So when you do:
SendDataTimer.Change(0, 3000);
0 implies the callback will be called every 0 ms...
[update] I hate it when the documentation lists the parameters the wrong way around!
0 implies the callback will be called immediately [update]
modified on Wednesday, May 28, 2008 9:45 AM
|
|
|
|
|
Use of System.Threading.Timer requires a lot of thought because the callbacks always occur on the thread pool. This means they almost always fire on a different thread to the one that created the timer, that they can run concurrently if the callback function takes a long time to execute, and conversely can be blocked indefinitely if the thread pool is busy.
It is generally much safer to use a System.Windows.Forms.Timer , as long as you're running a message loop (Application.Run ) on the thread. This causes the callback to be fired on the thread that created the timer when no other message is outstanding after the timer duration has passed. (This class maps directly to the operating system's SetTimer call.)
When you're debugging, you're typically stepping through code much more slowly than once a second, so the timer could well be firing another callback while you're still debugging it. You need to ensure that this isn't what you're seeing.
I can't see a problem with using GetProcesses , except to note that there's also a GetProcessesByName method which could simplify your code a bit. (Internally, this method calls GetProcesses , though, and copies the matches to an ArrayList and then to another array, so it actually produces more garbage.)
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
How can I configure my .net solution/project to allow File IO Permissions? I'm trying to access a .xml file on my hard drive and I get the following error: Request for permission of type 'System.Security.Permissions.FileIOPermissions... failed.
Thanks for your help, Lisa
Lisa
|
|
|
|
|
Either you are running in less than full trust, or you do not have the security permission to access that file.
Is this a web application?
|
|
|
|
|
No this is not a web application. It is a very simple learning winforms Windows Application.
1. On my project / properties / security page I have "This is a full trust application" radio button selected.
2. I created the xml file I am trying to access.
3. I inherited a winforms / C# application, when I try to access files in that solution / project I do not get any errors. I created a new Windows application (solution / project) for my learning and within that project I am not able to access files.
Thanks so very much for your time and help. Lisa
Lisa
|
|
|
|
|
That is weird indeed. Can you post a full stacktrace of the exception, maybe it can be deciphered that way.
|
|
|
|
|
Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessPermission.Demand()
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
at System.Threading.CompressedStack.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
at System.Xml.XmlTextReaderImpl.OpenUrl()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at System.Xml.XmlDocument.Load(String filename)
Lisa
|
|
|
|
|
This sounds weird.
Can you try the application on another PC? That would tell you if your 'machine' permissions are broken.
What happens when you try load that XML file from a simple console application from your PC?
What is the filename you pass into it?
|
|
|
|
|
The error is caught on the following statement.
Doc.Load("c:\\vs\\Employees.xml");
If I try to run the code from a different .NET Windows Application on my PC it works fine. I did not setup that application, I inherited it from someone. Any new Windows Application that I setup the File IO Permissions does not work.
I really appreciate all you thoughts and suggestions. Thanks, Lisa
Lisa
|
|
|
|
|
It sounds like your security permissions is messed up. You say someone else worked on that PC? Then it is likely the administrator didnt 'clean' the previous users permissions, and thus conflicting.
|
|
|
|
|
|
Is this Vista or Windows XP? Is the XML file in the root of c: ?
|
|
|
|
|
I'm using Windows XP. The file is not in the root of c:, however I have also tried to get the Selected Path from a FolderBrowserDialog and I have the same problem.
When I try this in the Windows Application that I inherited I do not have the problem; that's why I think it is an "environment" problem.
Thanks for your help, Lisa
Lisa
|
|
|
|
|
Hey guys,
is it possible to change the color of individual rows in a DataDridView?
The data will be employees loaded into my application, the idea is to keep the row color of active employees white, make inactive - grey, make temporary - light green & make terminated - Red
any ideas where to start?
thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
HarveySaayman wrote: is it possible to change the color of individual rows in a DataDridView?
You could certainly do it via the 'CellFormatting' event by modifying the CellStyle.ForeColor and CellStyle.BackColor to whatever you desired. However, in that event you would need to change all the cells in the row to impact the entire row. There might be a way to do it automatically for the entire row as opposed to doing it cell-by-cell.
|
|
|
|
|
yeah cell by cell wouldn't be the best solution for this particular problem because each row has about 20 cells, and there will be a few 1000 rows at a time...
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
you.suck = (you.passion != Programming)
|
|
|
|
|
I need select from list containing product code and name but show only code in combo textbox.
Tried code below but dropdown list shows only code.
How to display both code AND name in selection list ?
using System.Collections.Generic;
using System.Windows.Forms;
class testForm : Form
{
testForm()
{
ComboBox cm = new ComboBox() { DisplayMember = "DisplayMember", ValueMember = "Code" };
List<Product> prodList = new List<Product>();
prodList.Add(new Product() { Code = "001", Name = "Wine", Cb = cm });
prodList.Add(new Product() { Code = "002", Name = "Beer", Cb = cm });
cm.DataSource = prodList;
cm.DataBindings.Add("SelectedValue", prodList, "Code");
Controls.Add(cm);
}
class Product
{
public ComboBox Cb;
public string Code { get; set; }
public string Name { get; set; }
public string DisplayMember
{
get
{
if (Cb.DroppedDown)
return Code + " " + Name;
else
return Code;
}
}
}
static void Main()
{
Application.Run(new testForm());
}
}
Andrus
|
|
|
|
|
hi
override the ToString() function in the product class and return the formated string with both properties.
regards
|
|
|
|
|
Thank you.
I tried code below but dropdown list shows only code.
How to force it to show both code and name ?
Andrus.
using System.Collections.Generic;
using System.Windows.Forms;
class testForm : Form
{
testForm()
{
ComboBox cm = new ComboBox()
{
ValueMember = "Code"
};
List<Product> prodList = new List<Product>();
prodList.Add(new Product() { Code = "001", Name = "Wine", Cb = cm });
prodList.Add(new Product() { Code = "002", Name = "Beer", Cb = cm });
cm.DataSource = prodList;
cm.DataBindings.Add("SelectedValue", prodList, "Code");
Controls.Add(cm);
}
class Product
{
public string Code { get; set; }
public string Name { get; set; }
public override string ToString()
{
return Code + " " + Name;
}
}
static void Main()
{
Application.Run(new testForm());
}
}
Andrus
|
|
|
|
|
try to add only the class object. do not set databindings. then in the selectedindexchanged event
cast the selecteditem to the class object.
Product product = (Product)myComboBox.Items[myComboBox.SelectedIndex];
|
|
|
|
|
Thank you. I tried the code below but TextBox in combo shows name also.
How to show only code ?
using System.Collections.Generic;
using System.Windows.Forms;
class testForm : Form
{
testForm()
{
MultiComboBox cm = new MultiComboBox() ;
List<Product> prodList = new List<Product>();
prodList.Add(new Product() { Code = "001", Name = "Wine" });
prodList.Add(new Product() { Code = "002", Name = "Beer" });
cm.DataSource = prodList;
Controls.Add(cm);
}
class MultiComboBox : ComboBox
{
protected override void OnSelectedIndexChanged(System.EventArgs e)
{
Product product = (Product)Items[SelectedIndex];
SelectedItem = product.Code;
base.OnSelectedIndexChanged(e);
}
}
class Product
{
public string Code { get; set; }
public string Name { get; set; }
public override string ToString()
{
return Code + " " + Name;
}
}
static void Main()
{
Application.Run(new testForm());
}
}
Andrus
|
|
|
|