|
Mycroft Holmes wrote: Now to do some research on MethodInvoker
It's just a delegate which can point to any method which will have no parameters.
|
|
|
|
|
[MSDN]This API supports the .NET Framework infrastructure and is not intended to be used directly from your code[/MSDN]
This would normally make me leery of using it.
N a v a n e e t h wrote: method which will have no parameters.
I presume this limitation is the reason it is not recommended. In which case the background solution will need to looked into as well.
Thanks.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
In that case you can create your own delegate with required parameters. I have seen many applications using MethodInvoker when you need to invoke a simple parameter-less method. I am not sure why MSDN say's not to use it.
|
|
|
|
|
Hi Mycroft,
getting the DataTable is what takes most of 10 seconds and needs to be delegated to a thread.
Your LoadGrid() method uses Invoke to cause the GUI thread to do it anyway, so your efforts to speed up things are pointless so far.
Here is unchecked code to get the DataTable on the thread and the DGV update on the UI thread;
it does not rely on any fancy C# code, it should work on all .NET versions:
private void LoadGrid(DataTable dtAttr) {
if (this.InvokeRequired) {
dtAttr = cashFlow.GetAttrForCashflow(cashFlow.CashflowID);
this.BeginInvoke(new LoadGridDelegate(LoadGrid), dtAttr );
} else {
UIUtils.dgLoad(dtAttr, dtAttr.DefaultView, "");
}
}
With anonymous methods/delegates you can further simplify it as others have shown.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi,
I am attempting to unit test some code i have written. Unfortunately I am having an issue when using a generic list of an object type I have defined. I'm basically checking to see that this list is equal to 0 and if it is return false. However when the check is performed I get a null exception error. Below is an example (not exact code) of the code I'm trying to test and the bold and underline is where i'm receiving the error. Thanks in advance to all that reply.
private Car _car = new Car();
//constructor
public CarValidation(Car carDetails)
{
if (carDetails == null)
throw new ArgumentNullException();
else
_car = carDetails;
}
public bool CheckForValues()
{
bool valid = true;
if(_car.OilPressure == null)
valid = false;
if (_car.TirePressure == null)
valid = false;
if (_car.GasAmount == null)
valid = false;
if (_car.Mp3SongsLoaded.Count == 0)
valid = false;
return valid;
}
|
|
|
|
|
car.Mp3SongsLoaded is null. Make sure you initialize it before using it, e.g. car.Mp3SongsLoaded = new List<string>();
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Thanks. Totally forgot to initialize the list.
|
|
|
|
|
Hi all,
I've been having a little problem with the WebClient class, and am hoping someone can help.
Here is what I'm currently working with:
<br />
string uri = "WebURL";<br />
<br />
byte[] postBytes = Encoding.ASCII.GetBytes(postString_Begin);<br />
byte[] postBytes2 = Encoding.ASCII.GetBytes(postString2);<br />
<br />
WebClient myClient = new WebClient();<br />
myClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");<br />
<br />
byte[] response = myClient.UploadData(uri, postBytes);<br />
<br />
string myresponse = Encoding.ASCII.GetString(response);<br />
<br />
response = myClient.UploadData(uri2, postBytes2);<br />
Here is where I hit my wall.
After I upload the first queryString, the next step in the process is returned.
The URL does not change, but when I go to post the next section of values, it posts them back to the first page/form part.
Can anyone point me to How I can post my second querystring to the returned page from the first request?
Thanks
|
|
|
|
|
Hi,
I have a form that contains a ComboBox and a DataGridView. The ComboBox gets populated with all the countries as seen in the code below:
private void PopulateCountries()
{
cbCountryId.DataSource = dsCountries.Tables["Country"];
cbCountryId.DisplayMember = "Country";
cbCountryId.ValueMember = "Id";
}
What I need to do is populate the DataGridView based on what country the user select. For example: if you select Australia then all the Australian states should display in the gridview. The code to display the states look like this:
private void GetStateByCountryId(int CountryId)
{
this.dsWBGT_V4 = dataCommunicator.GetStateByCountryId(CountryId);
this.stateBindingSource.DataSource = this.dsWBGT_V4;
}
As you can see I have a Property named CountryId but I cannot put it in the SelectedIndexChanged event because if the application start the event fires and I get an error because there was no selection in the ComboBox. I set the Property with this line:
CountryId = Convert.ToInt32(cbCountryId.SelectedValue);
Can anyone tell me how can I get the ComboBox to display a value by default at first run and set the property equal to that property so that the states in the selected country displays??
Illegal Operation
|
|
|
|
|
In your selectedindexchanged event test that there is a valid item
if(DGV.SelectedItems.count == 0)<br />
{return ;}
This is a common issue - an index changes twice - deselects on [0] and selects[4] so the event fires twice. This is needed for all collection controls, you just need to find the correct property to test for each control type.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thank you for the reply.
Excuse my ignorance but I have tried to add this code to the IndexChange event but I have no option of SelectedItems.count?
I have tried dgvState.SelectedRows.Count but obviously that does not work?
Illegal Operation
|
|
|
|
|
you can ignore the selectedIndexChanged Event whenever you want.
follow the steps to ignore the event and put it back when the form completly load.
comboBox1.SelectedIndexChanged -=comboBox1_selectedIndexChanged;
do your work here and then
comboBox1.SelectedIndexChanged +=comboBox1_selectedIndexChanged;
"comboBox1_selectedIndexChanged" is the selected Index Change event of comboBox1
|
|
|
|
|
All
I have an application that the client uses, we do release updates every few months and everytime there is an update we send them a CD.We decided to update app automatically.
The application uses an exe file along with 3 DLLs installed into GAC, while programming for auto updates I have no problem pulling the new files in to clients machine or with installing DLLs into GAC(because the DLLs have newer version number). But I am struck at replacing the original exe file, since the user clicks on a menu item that says "Get Updates", I don't see how I can replace the exe file without exiting the program itself!!!!!
Appreciate any help
~Sri~
|
|
|
|
|
Ah, the chicken-and-egg update problem.
What you'll want to do is spawn a separate to actually replace your executable and immediately close the app.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
i want to rename a file. i have one list view ,in this list view many files are listed. i want to rename a file just like we rename file in windows. how can i get this. any idea
thank you!
yogesh
|
|
|
|
|
Use File.Move (it's in System.IO).
"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
|
|
|
|
|
Set labeledit property to true. Handle AfterLabelEdit event to get notified when an item gets renamed.
|
|
|
|
|
Take a look at this[^], and take your pick.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
When running the following code "stream" is null anyone see why? I'm a noob. Is there a better way to get my embedded resources out of my build?
private static void ExtractFile()
{
Assembly Assemb = Assembly.GetExecutingAssembly();
Stream stream = Assemb.GetManifestResourceStream("LockOut_NA.Properties.Resources.ECLock");
FileStream fs = new FileStream(@"c:\ECLock1.htm",FileMode.CreateNew,FileAccess.Write);
StreamReader Reader = new StreamReader(stream);
StreamWriter Writer = new StreamWriter(fs);
Writer.Write(Reader.ReadToEnd());
}
Thanks in advance.
|
|
|
|
|
I guess the string passed to GetManifestResourceStream is incorrect. Call GetManifestResourceNames to see available embedded resources.
|
|
|
|
|
This is unlikely to be related to your problem, but using a StreamReader and StreamWriter to save it as a file is bad form. What if your resource contains a zero? What you could do instead is something like this:
public static void CopyStream(Stream source, Stream destination)
{
byte[] buffer = new byte[128];
long previousSourceIndex = source.Position;
int read = source.Read(buffer, 0, buffer.Length);
while(read != 0)
{
destination.Write(buffer, 0, read);
read = source.Read(buffer, 0, buffer.Length);
}
source.Position = previousSourceIndex;
}
Pass the manifest resource stream as the source, and a FileStream as a destination. Don't forget to close the Streams properly when you've finished - a using block would be helpful
|
|
|
|
|
Hello everybody, my problem is about DMX protocol. I want to create a program wich can handle the movement of some disco ligths. I mean, I want to create a software wich can manage the movement, and if is possible some other propierties of this kind of ligths. But this ligths work with a DMX protocol, they are conected into a bus (network topology), and I don't know the propierties of DMX protocol. Please, if someone know how to handle this protocol, if someone can give me an example on C#, it will be nice.
thanks to everybody
|
|
|
|
|
I have created two UserControls to try and resolve this.
namespace libSigCntrl
{
[ToolboxBitmap(typeof(ctrlBankBitSW))]
public partial class ctrlBankBitSW : UserControl
{
public ctrlBankBitSW()
{
InitializeComponent();
}
}
}
namespace libSigCntrl
{
[ToolboxBitmap(typeof(ctrlBitSW))]
public partial class ctrlBitSW : UserControl
{
public ctrlBitSW()
{
InitializeComponent();
}
}
}
The commented lines represent other attempts.
There are bitmaps for each of the controls added to the project
libSigCtrl
-
-
- ctrlBankBitSW.bmp
- ctrlBankBitSW.cs
.
.
- ctrlBitSW.bmp
- ctrlBitSW.cs
The Bitmaps have there "Build Actions" = been set to "Embeded Resource"
The Bitmaps are 16x16 at 16 color.
The Output Type is "Class Library".
This is driving me nuts.
|
|
|
|
|
There are two scenarios, and it would be useful to know which applies, in order to try to help.
Scenario 1.
You are looking to add one of your controls to a designer in the same solution as the controls, but you have not yet explicitly added your controls to the toolbox.
Scenario 2.
You have explicitly added your controls to the toolbox, and they do not display the assigned image.
Please say which.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I don't think either. I have created a project with to two controls in the project. The project is a class library that will hold a variety of "Controls" extending UserControl... Maybe it is Scenario 1. The user controls do show up in on my solution palette but with the default cog image. Does that help Henry. If now and I will try again to clarify.
Gregg
|
|
|
|