Posts

Showing posts from May, 2014

Donate

Apply ComboBox Border Color In VB.NET Windows Forms

Image
Here's a simple way to decorate border color in Combobox control. The solution is a conversion of C# code originally developed by a C# Corner forum member. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. AddHandler Me .Paint, AddressOf DrawBorder End Sub Private Sub DrawBorder( ByVal sender As Object , ByVal e As PaintEventArgs) Dim rect As New Rectangle( Me .ComboBox1.Location.X - 1, Me .ComboBox1.Location.Y - 1, Me .ComboBox1.Width + 1, Me .ComboBox1.Height + 1) Dim pen As New Pen(Color.Red, 1) Dim g As Graphics = e.Graphics g.DrawRectangle(pen, rect) End Sub Customized Combobox

Cannot assign <null> to anonymous type property (ASP.NET MVC Object RouteValues)

Image
After reading an article called ASP.NET MVC Partial Rendering by Stewart Leeks, I decided to download the code sample and gave it a spin. As I reviewed each classes and controllers, I needed to implement some changes on saving (ActionResult decorated by [HttpPost]) attribute. The updates would be to pass a value to parameter linkId so that I can add new record after editing a new one. The first solution I have in mind was to pass a -1 to linkID. This would work but, this will append a -1 to the url being requested. return RedirectToAction( "ListAndEdit" , new { linkId = -1 }); Image to anonymous type property (ASP.NET MVC Object RouteValues)" title="Cannot assign to anonymous type property (ASP.NET MVC Object RouteValues)"/> The second solution was to pass an object to the routeValue. However, this would append a System.Object to the request url. return RedirectToAction( "ListAndEdit" , new { linkId = new object ()}); Image to anonym...

Validate XML against XSD File In C# And VB.NET

In my nature of work, we dealt with XML files and schema on a daily basis. And here's a cool snippet on validating XML file against and XSD file. C# using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Diagnostics; using System.Xml; using System.Xml.Schema; using System.Xml.XPath; public class Form1 { private void Form1_Load(SystemObject sender, SystemEventArgs e) { XmlDocument myDocument = new XmlDocument(); myDocument.Load( "C:\\somefile.xml" ); myDocument.Schemas.Add( "namespace here or empty string" , "C:\\someschema.xsd" ); ValidationEventHandler eventHandler = new ValidationEventHandler(ValidationEventHandler); myDocument.Validate(eventHandler); } private void ValidationEventHandler( object sender, ValidationEventArgs e) { switch (e.Severity) { case XmlSeverityType.Error: Debug.WriteLine( "Error: {0}" , e.Message); break ; case ...

Simple Array CRUD Manipulation Using AngularJS Framework

Image
This weekend I decided to create a simple AngularJS CRUD array application. This example was based on Dan Wahlin's AngularJS tutorial. I simply reused the css and js files for simplicity sake. So, let's proceed with the actual scripts and html. Main HTML (Contains the input controls and div with ng-view directive which is the container of the partial view: <div data-ng-controller= "CustomerController" > <h3>CRUD application in AngularJS Array</h3> <hr /> Name:<br /> <input id= "inName" type= "text" data-ng-model= "inputData.name" placeholder= "name" /> <br /> City:<br /> <input id= "inCity" type= "text" data-ng-model= "inputData.city" placeholder= "city" /> <br /> <button class= "btn btn-pr...

HTTP Error 403.14 - Forbidden The Web server is configured to not list the contents of this directory (AngularJS)

Recently interested on AngularJS, I started reading Dan Wahlin's AngularJS material and downloaded the samples in Visual Studio 2012. Upon running the code, I encountered an error which is the title of this post. After days of testing, I noticed that the url doesn't change on runtime since each examples are treated as partial views loaded into a main view. This lead me to the right direction which is a solution from Microsoft on enabling defaultDocument in web.config. Web.config: <system.webServer> <defaultDocument enabled= "true" > <files> <add value= "home.html" /> </files> </defaultDocument> </system.webServer> Where home.html is the main html document which the partial views are loaded.

Register Composite Controls In ASP.NET Web.Config

After working on a simple composite control in asp.net, the last task was to register the control so that the asp.net page can consume it. I got it working by registering the control in web.config. Source: Register Composite Controls in web.config

Get Check Status Of A CheckedListBox Item Using Text Instead Of Index

There was a question raised on visual basic forums if you can access an item through it's name rather than index to get it's checked status. My suggestion was to implement a custom control. However, one of the resident MVP in that forum has a better solution using extension method which is simple yet elegant. Below are the extension methods in VB.NET and C#. VB.NET Module CheckedListBoxExtensions <Extension()> Function GetItemChecked( ByVal source As CheckedListBox, ByVal text As String ) As Boolean Dim item = source.Items.Cast( Of Object )().FirstOrDefault(Function(o) source.GetItemText(o) = text) Dim index = source.Items.IndexOf(item) Return source.GetItemChecked(index) End Function End Module C#.NET public static class CheckedListBoxExtensions { public static bool GetItemChecked( this CheckedListBox source, string text) { var item = source.Items.Cast< object >()...

Donate