Click here to Skip to main content
15,307,797 members

Comments by Midi_Mick (Top 82 by date)

Midi_Mick 4-Mar-17 1:16am View
   
No = the hashset contains all possible permutations, but only once each - it removes duplicates caused by the doubling up of letters. For example, if 5 different characters are entered, there are 120 permutations. However, if 2 of those letters are the same, of the 120 actual permutations, only 60 are distinct - each sequence of letters would be generated twice (once for the letter is the 1st position, and once for the letter in the 2nd position). The hashset removes those duplicates.
Midi_Mick 6-Feb-17 3:10am View
   
Nice example.
Midi_Mick 26-Jan-17 19:24pm View
   
You need to know which format is being imported. Otherwise, is 2/3/2017 the 2nd of March, or the 3rd of February? And if you CDate "1/25/2017" parsing with the British format defined, you will get an error, as there is no 25th month.

You might want to look at the TryParseExact method (https://msdn.microsoft.com/en-us/library/system.datetime.tryparseexact(v=vs.110).aspx) if you can try to summise what the date structure is going to be.
Note: If you parse without specifying a format, it will use whatever format is defined by your operating system - so you may get different results on different machines.
Midi_Mick 18-Jan-17 8:55am View
   
Close, but no cigar. Because of the massive changes made now, I think I might move this question into the C# forums, as discussion seems to be the go. Please don't flame me for doing so - this question as it stands has become invalid in its current state, and would become too large to continue it here.
Midi_Mick 18-Jan-17 6:48am View
   
I am creating classes for controls to be instantiated in a CommonFileDialog, using the IFileDialogCustomize interface. As such, my base abstract "Control" class has 2 properties common to all of the controls (ID and ControlState), and will know how to add themselves to the dialog (I declare an abstract AddToDialog method in the base control class). Depending on the type of control, it may contain other properties specific to that control, which would need to be serialised. One of these controls is also a "VisualGroup" control, which itself contains a list of other controls.
These controls are kept in a list within my main FileDialog class (which inherits from Component), and are added to the OS dialog just before they are displayed. I have a custom editor that allows me to enter that list at design time, and I am expecting the VS designer to serialise and deserialise the list as required. It is during the form designer's deserialisation of the list of controls that the error has been occurring - it all deserialises fine at runtime.
Midi_Mick 14-Jan-17 8:03am View
   
They are there in the code. All the classes defined are member classes of the CommonFileDialog Component, which contains the "DialogControls Controls" property. Each Control class inherits a uint ID property, and State property (which is an enum value), and a virtual AddToDialog() method, so the control knows how to add itself to the component. As mentioned, the problem occurs when I include a Control that contains a ControlGroup of other controls - There are numerous types that do this - The ComboBox above is an example.
Midi_Mick 14-Jan-17 6:40am View
   
1. I can't let the property have only a getter - it needs to be set by the UITypeEditor I have created to set the whole structure up.
2. I did try setting the Attribute to DesignerSerializationVisibility.Content, but I got a similar error with the same sort of symptoms. The error then occurred when setting a member of the Controls list, and it was complaining about the generic Type constraint (can't remember exactly what it said). However, resetting VS once again temporarily cleared the error, and the test program still worked fine.
Midi_Mick 14-Jan-17 5:43am View
   
Bugger - Didn't work (still same error).
However, I have narrowed down the occurrence of it to particular circumstances. I will edit the question to show the additional info.
Midi_Mick 6-Jan-17 21:47pm View
   
Actually Dave, the "&" in this case is n "reference to" operator, not an "address of" operator. If an address was being passed, the declaration would have used an "*" operator for its parameter. Subtle, but important difference.
Midi_Mick 5-Dec-16 5:51am View
   
https://www.codeproject.com/Tips/712072/Reading-an-Outlook-MSG-File-in-Csharp
Midi_Mick 4-Dec-16 7:44am View
   
Performance of the redraw will depend a lot on how many of the rows are actually visible in the viewport. However, by just setting the one row basically to invisible, it does not have to recalculate the layouts for any control that is not visible. You should find considerable improvement over your previous method of changing the control locations.
One other thing you should do, and it helps a lot, is to set call SuspendLayout for the TLP before setting the visibility of the contained controls, and call ResumeLayout after all modifications have been done - this will ensure only one redraw per set of modifications.
Midi_Mick 30-Nov-16 5:02am View
   
Yes - just forget about trying to convert to text - read the image data as a byte array, and save it to disk as that byte array unchanged.
If you want to apply huffman or rle compression, forget about text altogether and look up the algorithms (google "huffman image compression c#"). Apply them to your byte array before you save it. Then decompress using the appropriate algorithm when you read the data back.
Midi_Mick 30-Nov-16 2:31am View
   
You can't do that, unless you perform some sort of compression (in which case, the file is no longer text). The problem is that there are 256 possible byte characters, but only 96 ASCII text characters. To make the file sizes equal, you need to use binary characters, which is the image itself.
Midi_Mick 26-Nov-16 6:57am View
   
A couple of tricks with this technique. If you anchor both left and right, or both top and bottom, the control will shrink and grow horizontally or vertically respectively relative to the container size and resolution. If you anchor neither left or right, the control will centre itself in its container horizontally. So the trick is to make the containers resize with the form, and the controls to resize within their containers.
Midi_Mick 24-Nov-16 7:31am View
   
Yes, but you have to be careful. Take a look at my article on Safe Images from Streams http://www.codeproject.com/Articles/1135952/Safe-Images-from-Streams to get an indication of what can and/or cannot possibly happen.
Midi_Mick 21-Nov-16 4:52am View
   
thx - fixed.
Midi_Mick 20-Nov-16 22:46pm View
   
Thanks for that Mohtshm - I'd gone to bed by the time he replied.
Midi_Mick 20-Nov-16 10:36am View
   
Put
UpdateCommand = new SqlCommand(....
BEFORE you add the parameters. Note, you are setting the CommandText in the Constructor, so you don't need
UpdateCommand.CommandText = UpdateQueryString;
line.
Midi_Mick 20-Nov-16 10:16am View
   
That is very bad practice. You should be using your original statement, but add the parameters to the SqlCommand object.
You will have something like:

cmd.CommandText = UpdateQueryString;

You need to add:

cmd.Parameters.AddWithValue("@name", UUname);
cmd.Parameters.AddWithValue("@password", UUpassword);

...and so on
Midi_Mick 20-Nov-16 6:18am View
   
You make the class that is being bound internal. The binding is able to get public properties from an internal class ok. If you do need to expose the class to other projects, then just make an internal version of it for the purposes of the binding.
Midi_Mick 19-Nov-16 10:40am View
   
The data's getting into the database? Then which line is throwing the error?

I'm going to have to get back to this tomorrow, sorry. It's nearly 2:00am here.
Midi_Mick 19-Nov-16 10:01am View
   
Ok - well the typing of the @customer parameter seemed to work, as it moved on to the next parameter to report. I notice that DataGridViewCell.Value returns type object, so we may need to cast each parameter to its correct type. It may be better to go to the Add method, rather than the AddWithValue. The parameter adding will then look something like

md2.Parameters.Add("@customer", SqlDbType.Float).Value = rows.Cells[7].Value;

Take a look here https://msdn.microsoft.com/en-us/library/system.data.sqldbtype(v=vs.110).aspx for the various SqlDbType options. There is also an optional int parameter for the size if you are using fixed length strings in your database.
Midi_Mick 19-Nov-16 9:30am View
   
Ok - you may need to make sure that your parameter is the right type:
Try changing the line where you add the @customer parameter to
cmd2.Parameters.AddWithValue("@customer", Convert.ToDouble(rows.Cells[7].Value));

Also worth setting up the query in cmd3 as parameterized too, in just the same way as we just did for cmd2.
Midi_Mick 19-Nov-16 9:19am View
   
What type of field is customer? Is it text or numeric? And what are you adding to it?
Midi_Mick 18-Nov-16 18:33pm View
   
In Winforms, all you need to do is make sure none of your code is running. So long as the form is displayed, it will just sit there pumping the messages. Only while processing an event does this pattern take a break while the event is being processed (i.e. your code in the form is running).
Midi_Mick 18-Nov-16 7:29am View
   
I was going to go there for him too - just as soon as my head was straight enough. Well done mate. +5
Midi_Mick 17-Nov-16 4:37am View
   
Ok, now that you have included your Logger class definition, it's easier to answer.
Because you have declared sMessage as private, you will have to implement the Equals override in the Logger class (as per my answer above), as the Linq query does not have access to the field.
Note: If you override Equals, you also must override GetHashCode. In this case, I would simply return sMessage.GetHashCode() from that override.
Midi_Mick 16-Nov-16 12:16pm View
   
That works if Car inherits from Vehicle. However, his code shows an explicit cast defined, so it may be that Car is a member of Vehicle, and the explicit cast returns that member (which is why explicit casts are normally defined), in which case the above won't work. He'd need to leave out the "Where" under those circumstances.
Midi_Mick 15-Nov-16 18:10pm View
   
Compress it down to one line? Can't see anything simpler.

(model as IPrimaryRelatable)?.RelateToSource(sourceObject, env);
Midi_Mick 15-Nov-16 17:04pm View
   
You can, of course, use the ?. operator directly on the result of the "as" operation:

IPrimaryRelatable pRel = model as IPrimaryRelatable;
pRel?.RelateToSource(sourceObject, env);
Midi_Mick 13-Nov-16 11:21am View
   
I think, looking at the code, that the 2nd assignation of Label1Data is just a typo - should be Label2Data.
Otherwise, all comments good. However, if he removes the inheritance of Thread1 from Form1, and corrects the typo, I think it might actually work as he expects. Not pretty, but working. He might also need to put an Application.DoEvents() call after the Sleep to get the updates displaying at the appropriate intervals, rather than all happening at the end.
Midi_Mick 11-Nov-16 4:06am View
   
Apologies. The Matches declaration should be a MatchCollection. Fixing answer
Midi_Mick 10-Nov-16 7:41am View
   
Yes - in the click event, just check the ((Control)sender).Parent property. That will be whatever control contains the control that was clicked, so you can get ((Control)sender).Parent.Name, or whatever. Note, for controls that are directly on the form, this will be the form itself - you might want to check for that.
Midi_Mick 10-Nov-16 4:32am View
   
You are right. GroupBox doesn't inherit from ContainerControl. Who'd have thunk. Will update my solution to suit. Thank you.
Midi_Mick 10-Nov-16 4:16am View
   
Deleted
You are right. GroupBox doesn't inherit from ContainerControl. Who'd have thunk. Will update my solution to suit. Thank you.
Midi_Mick 9-Nov-16 17:11pm View
   
Did you do what I did first up, and in the foreach, forget to change "Controls.OfType" to "control.Controls.OfType"? Or perhaps the braces around the outside of the button.Click+= and the if statement?
Midi_Mick 9-Nov-16 12:21pm View
   
I actually thought of that, but that then means anything over 100 is valid up to 149, and invalid if greater than that, which didn't sit well with me, so I threw it out. It is also incorrect in that scores between -1 and -49 also return 0, not -1, so appear as a fail rather than invalid.
Midi_Mick 9-Nov-16 11:23am View
   
So, you add properties and/or methods that change the content.
Midi_Mick 8-Nov-16 8:58am View
   
How DARE they! I'd not have picked that as an option. I guess to see it, you'll need to make a copy of the message and send it to Gmail as the only recipient. However, I reiterate, how DARE they!
Midi_Mick 6-Nov-16 11:30am View
   
Sorry - but that code is a bit on the messy side. You are probably going to have to tidy it up, and do bits of the code at a time to see where the bottleneck is.
What I would suggest is get rid of the Task - await - async altogether, and do all the business work in the background worker. Don't do any UI at all in that worker thread. Just set up the LCT, then the DataTable, and then return. Finally, in the BackgroundWorker.RunWorkerCompleted event, add your UI tasks one at a time (i.e.
DGV_ListEditCustomer.DataSource = table;
SetColumnsEditCustomerList();
See which of these 2 statements, if either, cause the hold-ups. I can't see the SetColumnsEditCustomerList method in your code there, but I am suspecting that that one is your culprit.
Midi_Mick 6-Nov-16 9:25am View
   
Just an exercise using your richtextbox example - put a "Sleep(1000)" in that for loop, and try to keep the UI responsive while it updates. I think you'll see my point.
Midi_Mick 6-Nov-16 9:22am View
   
I realise it is just an example, but you are wrong about the "Invoke" being the same as the "BeginInvoke". Invoke actually waits for the message to be processed before proceeding. BeginInvode returns immediately, and only processes the delegate when the UI thread is available. Because you were invoking the delegate with the for loop in it, that for loop was being executed on the UI thread - locking everything else out.

For what you are actually doing, load the data in your background thread. Do not attempt to update anything while this is happening, unless you can do it with a very brief action. And if the update is not state-sensitive, use the BeginInvoke instead of the Invoke to do it. Then, once the load is complete, start updating the UI. If that, too, is a slow process, do it one bit at a time from a background thread, just Invoking the minimal update as necessary.

To get decent responsiveness, you need to fully separate your business logic from the UI. Partially separating them is often not enough.
Midi_Mick 6-Nov-16 6:17am View
   
Just a quick observation: Why Update username when it hasn't changed - if it had, the WHERE clause would fail?
Midi_Mick 6-Nov-16 1:13am View
   
No worries - it was a fun one, and had me scratching up a bald patch for a little while. But once I hit upon that what you needed was an array of arrays, the answer became obvious.
Midi_Mick 5-Nov-16 8:27am View
   
Also, your return statement will error - don't include the square brackets. C# doesn't like that. Improving Mehdi's answer to include that.
Midi_Mick 1-Nov-16 1:18am View
   
Please, let me know if you understand WHY each of these are needed. This is very basic OOP programming, and without understanding Why, you will not get very far as a programmer, I am happy to help you understand, but try to get a grasp yourself if you can.
Midi_Mick 31-Oct-16 13:10pm View
   
No worries - happy to help
Midi_Mick 31-Oct-16 12:39pm View
   
But a TextBox does not have an Items property. If it is a multi-line textbox, you will have to add all the info with to the Output.Text property with a newline ('\n') separator. However, if you don't need to edit the text, I'd possibly look at using a ListBox control instead - that has the Items property you're using.
Midi_Mick 24-Oct-16 11:25am View
   
Also, every time your timer fires, it will create a new form for stuff that's already been done. Either you need to stop the timer after you've processed the clipboard, or you need to keep tabs on which bits of text have already had a form created for them, and not do it again.
Midi_Mick 21-Oct-16 6:05am View
   
Yes - at end. Both the above produce an IEnumerable<string>, which can be converted to a list, array, or even a few other more complex containers.
Midi_Mick 21-Oct-16 4:38am View
   
Putting your answer in a Solution so it can be formatted...see below (in a few minutes)
Midi_Mick 19-Oct-16 8:49am View
   
Not really - a bit too much work involved. However, a quick search of CP for "PrintDocument" gave me these 2 pages (plus more) that have all the info you need to do this:
http://www.codeproject.com/Articles/16720/Basic-Text-and-Image-Printing
http://www.codeproject.com/Articles/9907/Output-graphics-files-using-your-printing-code
Midi_Mick 19-Oct-16 7:48am View
   
You can almost certainly do what you want with linq - I'm just not sure what you are expecting as a result. You have your Dictionary which has a value that is a list of products. Given your input, are you just after a single list of products garnered from all the lists, or are you after a list of keys that have an associated list of products that match your input, or maybe a list of lists, each of which contain a product that meets your criteria?
Also - you say that your Dictionary's key is the PRODUCT_CODE, and PRODUCT_CODE can be null. It is not permissible to have a dictionary key of null, so I assume you've already translated that to "UNKNOWN" before you create the dictionary.
Midi_Mick 18-Oct-16 5:38am View
   
There's no "quick answer" here. You would need to hire a at least a couple of developers for two or more years, preferable with experience in image processing and a smidgen of AI thrown in, to get something like this happening for you.
Midi_Mick 18-Oct-16 4:25am View
   
I'm actually trying to work with the Windows Property System. I instantiate an object exposing the IPropertySystem interface with a call to PSGetPropertySystem - that works fine. Then when I try to use that interface to call, say IPropertySystem.GetPropertyDescriptionByName - that error occurs. I've declared the interfaces with the COMImport attribute.
Midi_Mick 15-Oct-16 13:35pm View
   
Well, I've worked around the issue, by making the collection an array, and doing standard serialization (I got rid of the TypeConverter altogether). Would still very much like to know why the structure I was using was failing, though.
Midi_Mick 14-Oct-16 5:00am View
   
or, for a faster result, every 16th element could be done with a bitwise operator rather than the modulus operator i.e. (i & 15) == 0
Midi_Mick 7-Oct-16 8:39am View
   
Deleted
That semi-colon before the two brackets at end of 3rd line shouldn't be there. Telling you in message here because the "Improve Solution" is doing some weird sh*t ATM.
Midi_Mick 6-Oct-16 11:16am View
   
In that case, your only other option is to intercept the KeyDown event on your form, after having set the KeyPreview on the form to True. Note that this interprets only one key at a time, so you would have to look at the 2nd key press in the KeyDown event of your menu.
Midi_Mick 30-Sep-16 4:56am View
   
That's none of my business - I don't need to know the reason people want (or need) to do something in order to help them do it if I am able.
Midi_Mick 30-Apr-16 23:51pm View
   
Useful information about multiple data readers on a single connection can be found here:

https://blogs.msdn.microsoft.com/angelsb/2004/09/07/ado-net-2-0-multiple-active-resut-sets-per-connection-in-sql-server-2005-mars-faq/
Midi_Mick 11-Mar-16 8:59am View
   
Ta mate - that's exactly what I have now - was just wondering if I was doing it right (I'm definitely NOT an SQL guru). I'll get in and mark this as solution once I leave a bit of time for other possible opinions.
Midi_Mick 28-Jan-16 19:52pm View
   
you can't use a switch, as case statements must be a constant.
Midi_Mick 4-Jan-16 11:10am View
   
Will do
Midi_Mick 4-Jan-16 8:20am View
   
Weird: I cant get the solution to put the asterix in the".*?" - take my word for it, its there (not just .?).
Midi_Mick 4-Jan-16 7:37am View
   
Something interesting that could do with explanation, if you know: I tried putting a non-capturing look ahead at the end (to tell the non-greedy capture where to stop), as below:

@"(?'1'(animal:)|(mineral:)|(vegetable:).*?(?=(animal:)|(mineral:)|(vegetable:)|$))"

I get three matches once again, with only the second one being as expected. The first and the last match are just the keywords ("animal:" and "mineral:", while the 2nd is the expected "vegetable: timber, potato. ". Scratching my head here.
Midi_Mick 4-Jan-16 7:13am View
   
Nope - no good. Wouldn't have expected it to work, but as I am fairly inexperienced with regular expressions, it was worth a shot. With a space, the ". *?" would be a non-greedy match for any character followed by 0 or more spaces.
Midi_Mick 24-Dec-15 15:13pm View
   
Interesting. The optimising compiler obviously isn't as good as it really should be. I'll keep that sort of thing in mind when writing my own time critical code.
Midi_Mick 23-Dec-15 9:20am View
   
Are you looking for x.ID == "111,222,333" or x.ID == "111" or "222" or "333". If the former, then you already have it right. If the latter, then you could do something like

_DataInfo.Where(x=> _id.Split(',').Contains(x.ID));
Midi_Mick 4-Dec-15 21:07pm View
   
That's also my line of thinking...a pain, but so be it. It gets mre complicate insofar as uppercase could be lowercase, but not both, and remove could have different things (not just punctuation) associated with it. I figured though, if I could just get the "any order optional" bit sorted, I could have handled the rest.
Midi_Mick 4-Dec-15 21:01pm View
   
That would be cool if I wrote the command processor - which I didn't. I am just calling it, and I need to make sure that arguments entered are valid before I do.
Midi_Mick 4-Dec-15 20:20pm View
   
No - the arg1 to arg6 stand alone (i.e. not labels). so the command could be something like:
"process uppercase remove punctuation", where "uppercase" is one valid argument, and "remove punctuation" is another valid argument.
Midi_Mick 29-Nov-15 23:13pm View
   
I actually get 6/6 - but I'm in Australia, where we use dd/MM/yy rather than MM/dd/yy. And because TryParse picks up on the localisation, it works when the format is localised.
Midi_Mick 29-Nov-15 12:01pm View
   
That one was close, and had generally the right sort of idea. It was missing stand-alone times, GMT offsets, and seconds/milliseconds in the times, though.

It took me hours, but posting below what I eventually came up with
Midi_Mick 29-Nov-15 4:10am View
   
I'm not looking to validate - TryParse will do that for me - I'm just looking to find the text within the document to pass to TryParse.
Midi_Mick 29-Nov-15 2:30am View
   
There's quite a few. The thing is, the user will be entering them in the document manually - so they may like 29 Nov 2015 4:15PM, or the full word November, or 29/11/15. Or may they prefer Nov 29, 2015 or 11/29/15 if they're in the US. Then again, it may be a technical document, and the user has used the RFC standard "2015-11-29 16:15:00Z". Basically, anything the DateTime can parse, I want to be able to find.
Midi_Mick 15-Nov-15 21:20pm View
   
Damn that was quick :) http://www.codeproject.com/Tips/1056028/Simple-Custom-Collection-Designer-Support
Midi_Mick 15-Nov-15 19:32pm View
   
Tip/Trick submitted - I'll post a link to it in here once it is published.
Midi_Mick 15-Nov-15 4:03am View
   
Absolutely! :)
Midi_Mick 15-Nov-15 1:54am View
   
Thanks for those suggestions/links George. I already looked at that first article, and that got me as far as I had gotten. Read the other two since, and not really a lot of help there, either (as they all seem to used standard collection objects). So I started looking down the line at what those standard collections exposed that I didn't - which gave me my solution below.
Midi_Mick 5-Nov-15 9:46am View
   
Yep - that did the trick. Ta muchly.
Midi_Mick 12-Oct-14 2:18am View
   
I note in the code for the main form, the loop where you are trying to get the contents is inside the loop where you are adding the item to the listbox - I don't think that is what you want.

Also, the inner loop is not dereferencing stringlist as being the member of Utils. You may have a member of MainForm called stringlist (allowing the test to compile), but that will be a different instance to the stringlist in utils.