Posts

Donate

Change DataGridViewRow FontStyle To Bold In CellFormatting Event

Hello, There was a question raised in the forums on how to change the FontStyle of a DataGridViewRow to Bold in the CellFormatting event. A solution is to set the Font property of a row with a Font object setting it's second parameter to FontStyle.Bold. private void EmployeeDTRDataGridView_CellFormatting( object sender, DataGridViewCellFormattingEventArgs e) { if (EmployeeDTRDataGridView.Columns[e.ColumnIndex].Name == "OnLeave" ) { if (e.Value != System.DBNull.Value) { if (Convert.ToBoolean(e.Value) == true ) { EmployeeDTRDataGridView.Rows[e.RowIndex].DefaultCellStyle.Font = new Font(e.CellStyle.Font, FontStyle.Bold); } } } }

Rounded Corner Button Example In WPF

Image
In WPF, you can alter the corner radius of a button using Style class. In Setter class, set the Property value to Template. Inside the Setter class, add a ControlTemplate class that will target the Button control. After that, you can add a Border class and then setting it's CornerRadius property with an integer value of the desired radius. The example below is a user control that has a Button and a Style resource that will alter the Button's corner radius. User Control <UserControl x:Class= "WPFButtonCornerRadiusXAMLVBForums.UCRoundedButton" xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x= "http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc= "http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d= "http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable= "d" d:DesignHeight= "45"

Using Bootstrap Typeahead.js Plugin In ASP.NET MVC Project

Image
Hello all, Bootstrap has lots of plugins that you can experiment with, and one of them is the Typeahead.js plugin similar to jQueryUI Autocomplete plugin. According to Bootstrap, Typeahead is an extendend plugin for quickly creating elegant typeaheads with any from text input. So given the description of the widget, I will provide a tutorial that integrates the plugin in an ASP.NET MVC project basing from this article Twitter Bootstrap Typeahead and ASP.NET MVC . The author from the source demonstrates preloaded country values but in my case, I modified it to handle searching through a database. So to proceed with, just follow the steps below: 1. Create an ASP.NET MVC Project (C#). 2. Add an ADO.NET Entity model that connects to the AdventureWorks DB and it's CountryRegions table. 3. In your home controller, add the code that search countries based on a given value. private static AdventureWorks2012Entities _context; // // GET: /Home/ public ActionResult Index() { ret

Find Elements In XML From List Collection Using LINQ And C#

Hello, Given you have a List object with a number of string elements and you want to check whether the elements in the list are found in the XML file, options are your going to use the for each loop or the List.ForEach() action to traverse the List and perform searching through the XML file. XML File <?xml version="1.0" encoding="utf-8" ?> <catalog> <book id= "bk101" > <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description> An in-depth look at creating applications with XML. </description> </book> <book id= "bk102" > <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price>

How To Read Or Parse XML Using XDocument In LINQ And C#

Given the XML file below which is a sample popularized my Microsoft, here's how to traverse with that XML file using LINQ to XML XDocument class. XML File <?xml version="1.0" encoding="utf-8" ?> <catalog> <book id= "bk101" > <author>Gambardella, Matthew</author> <title>XML Developer's Guide</title> <genre>Computer</genre> <price>44.95</price> <publish_date>2000-10-01</publish_date> <description> An in-depth look at creating applications with XML. </description> </book> <book id= "bk102" > <author>Ralls, Kim</author> <title>Midnight Rain</title> <genre>Fantasy</genre> <price>5.95</price> <publish_date>2000-12-16</publish_date> <description> A former architect battles corporate zombies, an ev

Using AJAX Control Toolkit AutoCompleteExtender In ASP.NET 4.5 Web Forms

Image
Hello all, I have posted in VBForums codebank on how to integrate Ajax Toolkit's AutoCompleteExtender control in your ASP.NET 4.5 Web Forms project. The thread is in VB.NET but if your using C# just replace the code behind as described in Step 4 with the snippet below. Code Behind private static AdventureWorks2012Entities _context; [ScriptMethod()] [WebMethod] public static List< string > GetCountries( string prefixText, int count) { _context = new AdventureWorks2012Entities(); var result = ( from country in _context.CountryRegions.AsEnumerable() where country.Name.ToLower().StartsWith(prefixText, StringComparison.OrdinalIgnoreCase) select country.Name).Take(count); return result.ToList(); } [ScriptMethod()] [WebMethod] public static object GetCountryInfo( string Country) { _context = new AdventureWorks2012Entities(); var result = ( from country in _context.CountryRegions.AsEnumerable() where country.Name.ToLower().Equals(C

Read Or Parse XML Using XPathDocument In C#

Good day! In this example, I will show you how to read an XML file using XPathNavigator and XPathDocument classes in .NET. When using these classes, make sure to include the System.Xml and System.Xml.XPath namespaces in your file. XML File <?xml version="1.0" encoding="utf-8" ?> <Invoice xmlns:inv= "http://salesorgchart.abcdefg.com" > <inv:Customers> <inv:TotalSales>134.49</inv:TotalSales> -<inv:Customer> <inv:Date>2013-11-15</inv:Date> <inv:Number>10001</inv:Number> <inv:CustomerName>Cherry Pie</inv:CustomerName> <inv:PONumber>30002</inv:PONumber> <inv:Address>Cebu City Philippines</inv:Address> -<inv:Products> -<inv:Product> <inv:Code>AE445</inv:Code> <inv:Category>Liquid Milk</inv:Category> <inv:Name>Devondale</inv:Name>

Show SQL Query Result As XML Using Sql Server FOR XML()

Image
Hello, Given that you are required to show the results of a query into an XML format, T-SQL has a function called For XML to achieve that output as shown below. Screenshot I have created two scripts to achieve the desired result as above. The first script will alias a column name with @AttributeName that signifies an attribute which will then be added to Assigned node using FOR XML Path() function. Use NorthwindCrudApp Go SELECT TOP 3 ProductID as "@ProductID" , ProductName as "@ProductName" , UnitsInStock as "@UnitsInStock" , UPPER (ProductName) as [text()] FROM Products As Products ORDER BY ProductID FOR XML PATH( 'Assigned' ), Root( 'DATA' ); The second script also creates column alias for each column using the syntax NodeName/@Attribute similar to an XPath expression. SELECT TOP 3 ProductID as "Assigned/@ProductID" , ProductName as "Assigned/@ProductName" , UnitsIn

Set DataGridTemplateColumn Control to ReadOnly in WPF

Image
Hi all, There was a question raised on how to set a control (ex. TextBox) inside the DataGridTemplateColumn of a WPF DataGrid to ReadOnly. The solution to that is to get the DataGridRow followed by accessing the DataGridCell and then get the VisualChild control inside the DataGridCell. By then, you can set the control's property IsReadOnly to true . XAML Code <DataGrid x:Name= "dgPerson" Grid.Column= "2" Grid.Row= "2" CanUserDeleteRows= "False" AutoGenerateColumns= "False" CanUserAddRows= "False" > <DataGrid.Columns> <DataGridTemplateColumn Header= "ID" Width= "150" > <DataGridTemplateColumn.CellTemplate> <DataTemplate > <TextBox Name= "txtID" Text= "{Binding ID, Mode=OneWay}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <DataGridTemplateColumn H

Invalid postback or callback argument in ASP.NET (_doPostBack in jQuery UI Confirmation Dialog)

Hello, I'm currently working with ASP.NET GridView control that shows a confirmation dialog using jQuery UI instead of the classic JavaScript confirm dialog that prompts a user to delete a certain record. However, integrating that with the GridView control was slightly tricky in the sense that I was stuck with Invalid postback or callback argument error. Since this is ASP.NET Webforms, you have to deal with Postback hell issues. :) jQuery UI Dialog that trigger's postback buttons: { "Yes" : function () { __doPostBack(btnUniqueID, '' ); $( this ).dialog( "close" ); }, "No" : function () { $( this ).dialog( "close" ); return false ; } } After doing some research, I came up with two solutions. The first one is to set EnableEventValidation of Page directive to false for page level effect. Or you can set it in web.config for project scope. Page Directive Solution <%@ Page Language= "C#" AutoEventWire

Donate