Donald_a
Posts
-
Funniest S/W Company Name ? -
Bitwise Enum problem in Custom ControlI have a web custom control with the following property:
private AvailablePages _LinksToDisplay = AvailablePages.Home; public AvailablePages LinksToDisplay { get{return this._LinksToDisplay;} set{this._LinksToDisplay = value;} }
AvailablePages is an enum with the flags attribute set:
[Flags()] public enum AvailablePages : int { Home = 1, AddNewCCRate = 2, AddNewCCRateValue = 4, AmendCCRateValue = 8, AddNewForecastRate = 16, AddNewForecastRateValue = 32, AmendForecastRateValue = 64, AddNewRate = 128, AddNewRateValue = 256, AmmendRateValue = 512 }
This works if only one enumeration is chosen through visual studio's web forms designer. Code is written to the control's tag on the .aspx page along the lines of:
LinksToDisplay="Home"
However, when multiple values are chosen, the designer writes something like:LinksToDisplay="Home,AmendCCRateValue"
and the page throws an "Object reference not set to an instance of an object" error before any code is run (EG can't get it to stop at a break point before it fails). The stack trace starts:[NullReferenceException: Object reference not set to an instance of an object.] System.Web.Compilation.CodeDomUtility.GenerateExpressionForValue(PropertyInfo propertyInfo, Object value, Type valueType)
I think this is a problem with the conversion from the comma seperated string to a bitwise enum, but have had no luck looking for a way around it. Any help will be much appreciated.
-
Concatenating 2 string arraysyou cannot re-dimension an array in C# like you could in VB with redim. You'll need to do something like:
//Two arrays string[] arrayOne = new string[]{"Hello", "World"}; string[] arrayTwo = new string[]{"Have", "a", "nice", "day"}; //Length of both together int newArrayLength = arrayOne.Length + arrayTwo.Length; //Set first to variable string[] arrayThree = arrayOne; //resize first to sum of lengths arrayOne = new String[newArrayLength]; //Add values from first (now held in temp variable) int iterator = 0; foreach(string s in arrayThree) { arrayOne[iterator] = s; iterator++; } //Add values from second foreach(string s in arrayTwo) { arrayOne[iterator] = s; iterator++; }
I'm sure theres a more diginfied way, but it does work!!!
-
Statistical Functions in C#I'm not sure exactly what you are after, but this may help?
using System; namespace NormInvFunc{ public class Normal { private static double Density(double x) { double y=Math.Pow (2*Math.PI ,-.5)*Math.Exp(-.5*x*x); return y; } public static double StandardNormal(double x) { double [] a=new double[5]; a[0]=.31938153; a[1]=-.356563782; a[2]=1.781477937; a[3]=-1.821255978; a[4]=1.330274429; double K=.2316419; double L=Math.Abs(x); double nx=Density(L); double q=1/(1+K*L); double S=0; for(int j=0;j<5;j++) { S+= a[j]*Math.Pow(q,j+1); } double SND=1-nx*S; if(x<0) { SND=1-SND; } return SND; } public static double StandardNormalInv(double R) { double Delta=1; double X=0; double Y=0; do { Y=X-(StandardNormal(X)-R)/Density(X); Delta=Math.Abs (Y-X); X=Y; } while (Delta>.000000001); return Y; } } }
NB will not return quite as many decimal places as excel. -
Timing Code ExecutionThanks for the replies guys. I actually found a very useful article here on CodeProject which may be of interest? Can be found at: http://www.codeproject.com/useritems/highperformancetimercshar.asp?target=timing Thanks again.
-
Timing Code ExecutionI need to time how long certain methods are taking to run to a very fine level. Too fine for using DateTime and TimeSpan. Does anyone know of any tools that i can use to analyse which methods are bottlenecks? Thanks
-
Web Service problemWhenever I create a web service on my machine, however simple, and try to invoke a webmethod, rather than returning the result to the browser as XML I am prompted to download a file of type .smi. This file, when saved, contains the xml i would normally expect to see in my browser. Any ideas how this can be fixed? Thanks in advance.
-
Counting num words in richtextThis will work assuming only one space is between each word:
this.richTextBox1.Text.Trim().Split(" ".ToCharArray()).Length;
-
Weird QuestionI think you can simply set the MDIParent property of each child window to null at runtime:
foreach(Form f in this.MdiChildren) { f.MdiParent = null; }
-
Keyboard hook + C# problemFurther to this, have a look at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks/hookreference/hookfunctions/setwindowshookex.asp It may not be the thread thing i mentioned above, but rather the idHook parameter needs changed? Although could equally be the dwThreadId parameter. Let me know how it goes!!
-
Keyboard hook + C# problemI think this is maybe something to do with which thread you hook up to? - If you are importing the SetWindowsHookEx method from user32.dll it takes a parameter for the thread you want to hook into, maybe this is where your problem is?
-
iterating controls on the formI was thinking of something more like:
//Sorted list to hold all controls SortedList ControlListByTabIndex = new SortedList(); //Loop over controls foreach(Control CurrentControl in this.Controls) { //Add to sortedlist, using the tabindex as the key, and the control itself as the value. ControlListByTabIndex.Add(CurrentControl.TabIndex, CurrentControl); } //You can now loop over the list, and it is ordered by TabIndex for (int i = 0 ; i < ControlListByTabIndex.Count ; i++) { Console.WriteLine(((Control)ControlListByTabIndex.GetByIndex(i)).TabIndex); Console.WriteLine(((Control)ControlListByTabIndex.GetByIndex(i)).Name); }
-
iterating controls on the formI don't think there is a way built into the framework to do this - would probably require the use of some kind of sortable collection EG SortedList or ArrayList...
-
Splitting a stringThis seems to work - i'm sure it can be optimised though:
//Your string string s = "0 @IQLNP-M7@ INDI" + Environment.NewLine; s += "1 NAME Benoni /THOMPSON/" + Environment.NewLine; s += "2 GIVN Benoni" + Environment.NewLine; s += "2 SURN THOMPSON" + Environment.NewLine; s += "1 AFN QLNP-M7" + Environment.NewLine; s += "1 SEX M" + Environment.NewLine; s += "1 SOUR @S01@" + Environment.NewLine; s += "1 BIRT" + Environment.NewLine; s += "2 DATE 14 Apr 1782" + Environment.NewLine; s += "2 PLAC Alstead, N.h." + Environment.NewLine; s += "1 DEAT" + Environment.NewLine; s += "2 DATE 24 Oct 1857" + Environment.NewLine; s += "2 PLAC Shalersville, N.h." + Environment.NewLine; s += "1 FAMS @F6073064@" + Environment.NewLine; s += "1 FAMC @F6073065@" + Environment.NewLine; s += "0 @IQLNP-KV@ INDI" + Environment.NewLine; s += "1 NAME Job /THOMPSON/" + Environment.NewLine; s += "2 GIVN Job" + Environment.NewLine; s += "2 SURN THOMPSON" + Environment.NewLine; s += "1 AFN QLNP-KV" + Environment.NewLine; s += "1 SEX M" + Environment.NewLine; s += "1 SOUR @S01@" + Environment.NewLine; s += "1 FAMS @F6073065@" + Environment.NewLine; s += "0 @IQLNP-L2@ INDI" + Environment.NewLine; s += "1 NAME Lovice /CRANE/" + Environment.NewLine; s += "2 GIVN Lovice" + Environment.NewLine; s += "2 SURN CRANE" + Environment.NewLine; s += "1 AFN QLNP-L2" + Environment.NewLine; s += "1 SEX F" + Environment.NewLine; s += "1 SOUR @S01@" + Environment.NewLine; s += "1 FAMS @F6073065@" + Environment.NewLine; //We are going to make our way through the string looking for Environment.NewLine + "0 " //this is our current index. int index = 0; //To hold indexes of found strings System.Collections.ArrayList indexList = new System.Collections.ArrayList(); //Start with zero indexList.Add(0); //Loop until none found while (index != -1) { //Look for index index = s.IndexOf(Environment.NewLine + "0 ", index + 1, s.Length - (index + 1)); //Add if found if(index != -1) { indexList.Add(index); } } //string array to, hold split strings string[] splitStrings = new string[indexList.Count]; //Loop over our indexes for(int i = 0 ; i < indexList.Count ; i++) { //if ots the last one - get string to end if(i == indexList.Count - 1) { splitStrings[i] = s.Substring(Convert.ToInt32(indexList[i]), s.Length -
-
Hiding close buttons, min and max in MDI CHildHavn't checked, but can this not be done with FormBorderStyle?
-
Derived DataGrid & Active Schema IssueI have created a custom web control that inherits from datagrid. It provides sorting on any data bound to it and allows for up & down arrows in column headers when a column is sorted depending on direction (asc/desc). This all works fine. However, when i place the control on a Web Form and try to add some columns EG:
<Columns> <asp:ButtonColumn Text="Button"></asp:ButtonColumn > </Columns>
Visual studio underlines the start tags in red with the messages: "The active schema does not support the element 'Columns'." and "The active schema does not support the element 'asp:ButtonColumn'." The code still runs fine, but intellisense is lost within studio. Within the original datagrid these tags are related to properties IE the Columns tag relates to the Column property etc.. and Visual studio knows what to do with these through attributes such as 'PersistenceModeAttribute'. I would have thought these would also have been inherited from the datagrid into my control, but these does not seem to be the case. I have tried overriding these Properties from within my control and adding attributes but this does not work/i don't know the correct attribute!! Another point to note is that when you open a tag within a datagrid tag in Visual studio, your options are limited (Columns, EditItemStyle etc..), however, within mine Studio pops up the usual list as with the root of the form (a, acronym etc..). I'd obviously like the earlier behavior in my control too. If anyone can help me make studio behave i'd be very appreciative. -
Web Custom Control & Custom Collection problemI have a custom collection of complex types. The type is 'GraphValue' and the collection is 'GraphValueCollection'. On my Web Custom control I have a property 'GraphValues' which is a GraphValueCollection. I have it set up such that the whole thing works through Visual Studio's designer & the control works fine at runtime. However, as soon as i use the designer to add a GraphValue to the collection & build the project, the designer shows the default "Error creating control" dialog with the tooltip saying '' could not be set on property 'GraphValues'. The '' is not my fat fingers either - its 2 single quotes!! The control still works fine at runtime - but this is a very annoying problem. I'm using the attributes ParseChildren(true) and PersistChildren(false) on the custom control class I'm using the attributes PersistenceMode(PersistenceMode.InnerProperty), NotifyParentProperty(true) and DesignerSerializationVisibility(DesignerSerializationVisibility.Content) on the Property. The Property has both Get & Set accessors - I've seen a similar post where somebody solved the issue by removing the set accessor, but if i do this the IDE crashes!! Any help to solve this much appreciated. Thanks Donald
-
Extending C# XML comment feature.My company wants to extend the XML comments feature of C# with some extra tags. I was wondering if anyone knows how to add extra tags to intellisense, so that they appear alongside the likes of , etc.. within the comment are above a member / class. Thanks in advance Donald