Hi everybody, Is there an attribute or some other way to validate that a property has a unique value. To illustrate what i mean, watch the "Name" property in the property grid of each control added to a windows form. It is unique! How can i achieve this capability too? Thanks in advanced, elaj
e laj
Posts
-
Unique names in property grid...? -
Custom Form problem...Hi, I had some forms that i have created long time ago... OK now i have created a special form that have three panels - the caption, footer and content. I want to use this form as a base form for my old forms. The problem is that the sub-controls of the form will not be visible - i had to manualy asign the controls as child of the content panel (that is - adds the controls to the content panels's Controls collection). Is there a way to make the designer put all controls of the form on its child controls collection, that is on the content panel controls collection. Thanks, elaj
-
no white spaces in enumHi MVPenn, Create your own attribute (you may wish to call it EnumDescription). You can find some examples over the net. For example: Example Recall that if you want to display friendly names for property name - you can use the "DisplayName" attribute. Unfortunately, this attribute can not be applied for enum members. Hence (as i said before) have to create your own enum description attribute. elaj
-
Event order sequence...Hi SkyWalker, There is nothing strange if your code does not depend on it. However, i wrote a code that that register to control's "LostFocus" event and do some job there. If the user call some other method - i unregister the event handler, but it should be done only after the "LostFocus" occurred. Because the the user traditionally will call my method in the "Validate" event, you may understand why this behavior raise some problems. However to overcome it i do the following: I registered to the "GotFocus" event, and within this event handler i registered to the "LostFocus" event. When the "LostFocus" event occurred, i do my job and unregistered the handler when it completed. Elaj
-
Event order sequence...Hi every body , (sorry for my english...) Suppose we have a text box (textBox1). If we "leave" this text box by pressing the TAB key, the order of the following events is: textBox1_Validated textBox1_LostFocus But, if we leave this text box using the mouse, that is by pressing on another control on the Form using the mouse, the order of these events is: textBox1_LostFocus textBox1_Validated This is strange behavior in my opinion. May anyone explain me this behavior? Thanks in advanced, elaj
-
Monitor SOAP body for webservicesDownload WebServiceStudio from: http://www.gotdotnet.com/team/tools/web\_svc This is a free toll that i hope meet your needs. e-laj
-
Description of property in property window [modified]There is an attribute DisplayName you can use it to customize the text displayed in the property grid. Have fun!
-
control in another formSet the "Modifiers" property of this control to public (or set the button access level to public by your self). After that you will be able to see that control in the intelisense from another form. Enjoy
-
Problem with ButtonEvents on dynamic UserContolsSorry - I have a little mistake, well i implement dynamic control creation long time ago - i forgot an important point. You should override the LoadViewState instead of TrackViewState. The TrackViewState is executed before the view state is populated with the previous value, LoadViewState is the right point to initialize dynamic controls according to view state values - in this point the view state has its previous values. Here is a full running example. In this example you can create dynamic buttons and executes their events. I wrote this example for you and any other who may need it. The DynamicExample.aspx ======================= <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DynamicExample.aspx.cs" Inherits="_Default" %> Untitled Page
buttons
Click Message:
Command Message:
The DynamicExample.aspx.cs ========================== /******************************************************************************* * * Filename: DynamicExample.cs * * Class: DynamicExample * * Creation Date: 06/Oct/2006 * * Update list: * ----------- * 1) Date: * Description: * * Writer: Ilan Amoyal (e-laj) * ******************************************************************************/ using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) {
-
scape sequence in insert queryI don't know a simple way. You should do: string str = "this is a 'sample string'"; str = str.Replace("'", "''"); thats all. Try it! elaj
-
Problem with ButtonEvents on dynamic UserContolsSee, Recall that the framework create the controls tree only for static controls - this is why the event of the dynamic controls could not reached there targets when the page is posted back - so this is your job, as i describe in a minute. The problem is that the page controls tree is built before the page load - and events that should be fired target to controls resolved in that stage. Hence if your dynamic controls are not existed in this level - WITH THE SAME ID AS THEY HAD IN THE PREVIOUS POSTBACK - the events will not be fired. So, a good solution will be: 1 - When you create the controls assigned them a unique id. Aparantly you will do it in the Page_Load, you should do it only if the page was not post bask. Dont forget to add you controls to the Controls Collection of their container. For example - if you add these controls directly on the form - Write: Page.Controls.Add(...your control here). Page_load... - if not post back - Create the control - Assigned the created control a unique id - Add the created control to its container "Controls" collection. 2 - When you create these controls - put some information in the ViewState so you can rebuild these controls when the page will be posted-back: - ViewState[some key]=information. The information should be encoded in a way that can describe you in the next step what controls were existed before the post back. 3 - Override the TrackViewState method of the page and rebuild the dynamic part of your page using the information you saved in the ViewState. Again dont forget to add these dynamic created controls to your Controls collection. That is all! If the dynamic controls that you are creating are always the same (obviously they are not) you could be satisfied with the Page_Load part without checking the PostBack status. Best regards, e-laj
-
Adjust to disable "Debugging Not Enabled" messagebox?First you may have to read this: from msdn. However VS automatically adds the debug=false to the compilation property in the web site project's web.config file. Hence you may have to change the VS template - to assign the value "true". Recall that you should set debug=false before deploying in order to remove all debugging information. VS template reference could be found in: Visual Studio Template Reference and you can find more articles on the web. Finally, there may be a very simple way to acomplish this - nothing that I know about. Best regards, elaj
-
QueryContinueDrag problemHi, I have a code fragment that handles dragging and dropping tree view nodes on each other, all in the same tree view. All works fine, but i want to cancel the dragging operation when two mouse button are presses. In MSDN is written: "The QueryContinueDrag event occurs during a drag-and-drop operation and allows the drag source to determine whether the drag-and-drop operation should be canceled. A QueryContinueDragEventArgs specifies whether and how the drag-and-drop operation should proceed, whether any modifier keys are pressed, and whether the user has pressed the ESC key." Well i put a break point in this event, but in runtime when i press on another button or press another key - nothing happened - that is - i execution does not reach the breakpoint. I search over the internet, but NADA. Any help will be appreciated. elaj.
-
PropertyGrid HelpYour welcome! Now, to pertain id to its string, obviously you will create an object that have two properties (id and value) and override the ToString() to display the value. Ok, now if you use standatd listbox control in windows forms application, all objects that you will append to this control will be displayed using the string retrieved by calling to the ToString() method you just implemented. This leads you to what we call "CustomEditor". With CustomEditor you can create your own windows form like application to display and manage the property - so create one with listbox control to retrieve the records from the second table and adding them using the custom object you have just created. The last section in the mentioned MSDN article discusses this issue. Best regards, elaj
-
PropertyGrid HelpYou should implement your own TypeConverter in order to enable conversion from string type to integer type and vice versa. Implementing new type converter is an easy job. Here is a link to very good tutorial: From MSDN Another example: Descriptive Enumarations
-
String with escaped squences...After wasting some time writing the method, Rob Graham give me a clue. Rob Graham, you are right this method is in .NET 3.0, but there is another method with the same name: Regex.Unescape This function do the job. BUT, this method is not error tolerant like my method;P. So, if someone meant to use unescape and want to skip invalid escape sequences - my method does it. Rob Graham - Thank you, again!
-
String with escaped squences...First, thank you all for trying to help me, as i said, it seems that there is no built in method for escape sequences substitution. Hence i set down and wrote the following method, hopefully with no bugs. In the method i use scanning instead of serching and replacing as well as some bitwise operations in order to enhance performance. The reverse method is much simpler to code. Finally, here in Israel we celebrate a new year - so happy new year to you all. Here is the method. /// /// Substitutes the escape characters in the specified string with their appropriate characters. /// /// The string. /// The string after the escape characters were replaced by the appropriate character. /// /// If the method encounter invalid escape character, the backslash character is removed and /// the character that comes right after it is copied with no change. /// public static string SubstituteEscapes(string str) { StringBuilder sbResult = new StringBuilder(); bool bEscaped = false; for(int i = 0; i < str.Length; i++) { char current = str[i]; if(bEscaped) { switch(current) { case '\'': case '\"': case '\\': /* Merely append the current character. This is the default behavior */ sbResult.Append(current); break; case '0': /* The '\0' (string terminator) character \u0000 */ sbResult.Append('\0'); break; case 'a': /* The bell (alarm) character \u0007*/ sbResult.Append('\a'); break; case 'b': /* The backspace character \u0008*/ sbResult.Append('\b'); break; case 'f': /* The form feed character \u000C*/ sbResult.Append('\f'); break; case 'n': /* The line feed character \u000A*/ sbResult.Append('\n'); break; case 'r': /* The carriage return character \u000D*/ sbResult.Append('\r'); break; case 't': /* The tab character \u0009*/ sbResult.Append('\t'); break; case 'v': /* The vertical tab character \u000B*/ sbResult.Append('\v'); break; case 'u': /* Unicode character (exactly four digits to read on) */ try { char ch = (char)int.Parse(str.Substring(i + 1, 4), NumberStyles.AllowHexSpecifier); sbResult.Append(ch);
-
String with escaped squences...Well, they are. However it seems up to this point that there is no such built in method, hence i am writing such method now. The principle is a little more complicated than seraching and replacing, consider the \uxxxx unicode escapes, \xd[d][d][d] hexadecimal escapes (variable length up to 4 digits) etc. At the moment i finish this method (soon) i post it.
-
String with escaped squences...The idea is to enable the user to enter string constants that contains escape character - eaxactly as we do when we edit our source code in VS. For example, the user maybe enter the following text in some text box: "Hello\there\nand\there. But \\this is a backslash and not a tab chracater" So, when i get this string, .NET framework treats these sequences as is and not as escape character - this is the expected behavior. If you add a breakpoint at the right point and watch this user input in the debugger you will see: "Hello\\there\\nand\\there. But \\\\this is a backslash and not a tab chracater" However, i was wondering if there is a simple way, that is method supplied by the framework that do the job of escape character substitution as well as the reverse job. So when i get this string i do the following: string result = SubstituteEscapes(userInput); ...and the result will contains the same string after the "\t" replaced by the tab character and the "\n" replaced by the new line character and the "\\" will be replaced by a single "\". and the reverse way should be: string original = SubstituteSpecialCharacters(result); ...and the the tab, new line and backslash characters will be replaced with the appropriate escape sequences. It is possible to search and replace those escapes even by using regualr expressions. But does the framework has a built in method for that? Why? You may ask your self why i need these methods? Well i use a ProperttyGrid and ask the user what should be the seperator string between fields in the log file. Beacause pressing tab move the focus to the next property in the grid, and also because copying and pasting tab is BAD solution to this problem, i want to give the user the possiblity to enter escapes. Thanks, again!
-
String with escaped squences...Is there a simple way to parse a string that contains escape character to the appropriate string, and vise versa? For example, given the following string: "hello\tthere" should be parsed to: "hello there" and vs. I need these methods because i let the user to enter escape chracters within the strings. Thnaks!