Error: the controls collection cannot be modified because the control contains code blocks with Calendar Ajaxcontroltoolkit No Comments



This error happened on one of my colleague when he tried to use the Calendar extender from AjaxToolKit. It took an hour just to resolve this issue, but before we resolved it we got an idea that something from Caledar Extender causing this problem because if we remove it the error is gone.

How to move form with borderless No Comments


  1. private const int WM_NCHITTEST = 0×84;
  2. private const int HTCLIENT = 0×1;
  3. private const int HTCAPTION = 0×2;
  4.  
  5. ///
  6. /// Handling the window messages
  7. ///
  8. protected override void WndProc(ref Message message)
  9. {
  10.     base.WndProc(ref message);
  11.  
  12.     if (message.Msg == WM_NCHITTEST && (int)message.Result == HTCLIENT)
  13.         message.Result = (IntPtr)HTCAPTION;
  14. }

Error in EF: Multiple object sets per type are not supported. No Comments



I have created an application which is using a Entity Framework Code first. And unfortunately, I encountered this error when I almost finished the member page. I solved this issue through searching in google as I have no idea of this error and I only see this once in my whole life in developing application. The issue was I have added 2 different entities into the DBContext that reference to the same table.

  1.  public class ADNContext:DbContext
  2.     {
  3.         protected override void OnModelCreating(DbModelBuilder modelBuilder)
  4.         {
  5.    
  6.             modelBuilder.Configurations.Add(new ServiceMap());
  7.             modelBuilder.Configurations.Add(new DentistServiceMap());
  8.            
  9.         }
  10.  
  11. // these 2 entities, they map to the same table
  12.         public DbSet<Services>  Services{ get; set; }
  13.         public DbSet<DentistServices> DentistServices { get; set; }
  14.  
  15.  
  16.     }

ExpandableObjectConverter does not work No Comments


Make sure any object/class property has initialized in order it to be expanded when displayed in the PropertyGrid.

If you don’t initialize it, it will not displayed in the PropertyGrid expandable.

Error: the type ‘T’ must be a reference type in order to use it as parameter ‘TEntity’ No Comments


I want to create a generic repository for my .Net application and I encountered this error.

After a couple of minutes searching for the solution as I am just a beginner, I found a way to solve this issue.

You just need to add a constraint into your generic class.

Example.

  1.  
  2. private IDbSet<T> Entities<TEntity>(Entity singleEntity) where TEntity:class
  3. {      
  4.     ObjectSet<TEntity> objectSet = context.CreateObjectSet<TEntity>();
  5.     objectSet.Attach(singleEntity);
  6. }

How to separate word using regex in c# No Comments



Here’s a simple implementation of regex replace to separate a word given that it is written in a Pascal case, example CompanyName. This function is every useful when you have an application with database driven.

  1.         private string ToSeparatedWord(string value)
  2.         {
  3.             if  (string.IsNullOrEmpty(value) ) return string.Empty;
  4.  
  5.             return Regex.Replace(value, "([A-Z][a-z]?)", " $1").Trim();
  6.         }

How to detect if the control is in design or run mode in constructor No Comments



It took me a day or two to figure out how to check if the control is in design mode or not. I use the DesignMode property of the control and being placed inside the constructor. DesignMode property is always returning false. I’ve almost lost hope on this and trying to find another way to address what want, that’s when I bumped into an unexpected results from the search engine which is absolutely the right one.

So here is what I have found, I use the LicenseManager.UsageMode to if the control is in design mode or not. However, you can still use the DesignMode property but not inside of the constructor.

How to create shadow on windows form No Comments


  1. private const int CS_DROPSHADOW = 0×20000;
  2.    protected override CreateParams CreateParams
  3.    {
  4.    get
  5.    {
  6.    CreateParams cp = base.CreateParams;
  7.    cp.ClassStyle |= CS_DROPSHADOW;
  8.    return cp;
  9.    }
  10.    }

Error:Attaching the script debugger to process iexplore.exe on machine failed. a debugger is already attached No Comments


I had this issue when I had to update my IE from version 9 to 10. Takes some time to find the solution but google is my friend. Here’s the solution that I used and its working.

64-Bit Systems: regsvr32.exe “%ProgramFiles(x86)%\Common Files\Microsoft Shared\VS7Debug\msdbg2.dll”

32-Bit Systems: regsvr32.exe “%ProgramFiles%\Common Files\Microsoft Shared\VS7Debug\msdbg2.dll”

Convertint C String to NSString No Comments


To convert c string to NSString you must use the stringWithUTF8String: method of the NSString class as illustrated below;

char *cString = “This is a c string.”;

NSString nsString = [NSString stringWithUTF8String:cString];
or
NSString nsString = [NSString stringWithUTF8String:"This is a string."];