Posts

Donate

WPF Datagrid (Prevent DataGrid Last Row From Being Sorted On Column Header Clicked)

Image
Here's the WPF version of prevent total rows from being sorted. Images: 1. Form Load, no column header is clicked (unsorted records) 2. Name header is clicked (sorting by column). The names are sorted alphabetically. Below are the methods used: /// <summary> /// column header clicked(sorting) /// </summary> private void dgProducts_Sorting( object sender, DataGridSortingEventArgs e) { DataRowView rv = (DataRowView)dgProducts.Items[dgProducts.Items.Count - 1]; if (rv[0].ToString().Contains( "Total:" )) { dvCopy = dgProducts.Items.SourceCollection as DataView; rv.Delete(); } sorted_aborted = e.Handled; } /// <summary> /// layout is updated /// </summary> private void dgProducts_LayoutUpdated( object sender, EventArgs e) { if (!sorted_aborted) { ...

Add Checkbox In WPF Datagrid DatagridTemplateColumnHeader (For Checkall)

Image
Hello, Here's how to add checkbox in WPF Datagrid DatagridTemplateColumn to simulate checkall. I have included the TSQL script, XAML and C# codes. Perform these steps below 1. Create an MSSQL database with the following Product Table schema below: Table: Products Fields: -    ProductID (int, autoincrement) -    ProductName (varchar) -    UnitPrice (decimal) -    QuantityPerUnit (varchar) -    Discontinue (bit)  SQL Script: USE [Your_Database_Name] GO /****** Object: Table [dbo].[Products] Script Date: 05/27/2013 14:07:39 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Products]( [ProductID] [int] NOT NULL , [ProductName] [varchar](50) NULL , [UnitPrice] [decimal](18, 2) NULL , [QuantityPerUnit] [varchar](50) NULL , [Discontinue] [bit] NULL , CONSTRAINT [PK_Products] PRIMARY KEY ...

Prevent DataGridView Last Row From Being Sorted On Column Click

Image
Hello, You might have a row in the DataGridView typically the last one that computes total and the grid control is unbound to a datasource. And then if a sorting event occurs, you dont' wanna include that row during sort event. So given that your application has a form and a DataGridView control, the code to perform databinding is handled in the Form Load Event. DataGridViewRow dgRowTotalCount; DataTable dataTable; private void Form1_Load ( object sender, EventArgs e) { DataTable dt = new DataTable( "tblEntTable" ); dt.Columns.Add( "ID" , typeof ( string )); dt.Columns.Add( "Amount" , typeof ( decimal )); dt.Rows.Add( new object [] { "1" , 100.51 }); dt.Rows.Add( new object [] { "2" , 200.52 }); dt.Rows.Add( new object [] { "6" , 500.24 }); dt.Rows.Add( new object [] { "8" , 1000.11 }); dt.Rows.Add( new object [] { "4" , 400.31 }); dt.Rows.Add( new object [] { "5" , 6...

Regular Expression Word Boundary Not Working If Using A Variable In C#

In this scenario, I have to match an exact state abbreviation (QLD) that is Queensland. I declared an array containing state constant values. Normally this would work without using a string variable in C#: Regex.IsMatch(address, @"\bQLD\b" ) However, this won't work: if (Regex.IsMatch(address, @"\b" + str + "\b" )) The solution is to put an @ sign on both "\b" of the expression: string [] states = new string []{ "ACT" , "NSW" , "QLD" }; foreach ( string str in states) { if (Regex.IsMatch(address, @"\b" + str + @"\b" )) { state= str; address = address.Replace(str, "" ).Trim(); break ; } }

ASP.NET MVP Design Pattern (Simple)

Image
Out of boredom, I decided to read some ASP.NET Articles and came stumbling to Dino Esposito's MVP Flavors . After reading it, I decided to translate this into an ASP.NET application. I revised specifically the Presenter class since this has most of the interaction. Below are some snippets and screen shots: Image: 1. Solution Explorer for the Sample ASP.NET MVP Site 2. On Drop Down Selection of Customer 3. Button Expand Is Clicked, Show other records on other textbox controls. Presenter Class: public class Presenter { private IDefaultView view; public Presenter(IDefaultView viewObject) { view = viewObject; } public void InitializeView() { : view.AddCustomer( "Alfreds Futterkiste" , "ALFKI" ); view.AddCustomer( "Ana Trujillo Emparedados y helados" , "ANATR" ); view.AddCustomer( "Antonio Moreno Taquería" , "ANTON...

Convert Time From A Specific Timezone To Another Using CONVERT_TZ() In MySQL

In this scenario, we have to convert a timezone from Central USA to Hongkong time. I took note of DST here from (-06:00) to (-05:00). Here's a sample query. SELECT CONVERT_TZ( '2012-09-12 04:35:00' , '-05:00' , '+08:00' ) as convert_to_ph; Cheers!

Adding An Item to WPF Datagrid (C#)

Hello! VB.NET Version: Adding An Item to WPF Datagrid (VB.NET) Here's the C# version of how to add an item manually to a WPF DataGrid. DataGridTextColumn c1 = new DataGridTextColumn(); c1.Header = "Test" ; c1.Binding = new Binding( "test" ); c1.Width = 473; dataGrid.Columns.Add(c1); dataGrid.Items.Add( new Names() {test= "just testing" }); Class property: public string test { get ; set ; } XAML code: <DataGrid AutoGenerateColumns= "False" Height= "289" HorizontalAlignment= "Left" Margin= "10,10,0,0" Name= "dataGrid" VerticalAlignment= "Top" Width= "481" Grid.ColumnSpan= "2" ItemsSource= "{Binding }" > </DataGrid>

Add An Item To WPF Datagrid (VB.NET)

Hello! C# Version: Adding An Item to WPF Datagrid (C#) There was a question on visual basic forum on how to add an item to a wpf datagrid. Here's a simple example below. Code view: Dim linkColumn As New DataGridTextColumn : Dim titleColumn As New DataGridTextColumn linkColumn.Header = "Links:" : titleColumn.Header = "Titles:" linkColumn.Width = dataGrid.Width / 2 : titleColumn.Width = dataGrid.Width / 2 linkColumn.Binding = New System.Windows.Data.Binding( "Link" ) : titleColumn.Binding = New System.Windows.Data.Binding( "Title" ) dataGrid.Columns.Add(linkColumn) : dataGrid.Columns.Add(titleColumn) dataGrid.Items.Add( New DataItems() With {.Link = "http://testingme.com" , .Title = "mytesting" }) XAML: <DataGrid AutoGenerateColumns= "False" Height= "289" HorizontalAlignment= "Left" Margin= "10,10,0,0" Name= "dataGrid" Ve...

CREATE DATABASE Permission Denied In Database ‘master’.

I successfully installed MSSQL Server 2008 in my working pc. But when I tried creating a database I encountered an error CREATE DATABASE permission denied in database ‘master’.  I recalled my username has no privilege as domain administrator. So, the solution was to  1. login on my  working pc as domain administrator 2. change server authentication to mixed mode 3. change password of sa. 4. reconnect using sa account That's it...

WPF TimePicker Control

Image
Based from these sources:  a. (http://jobijoy.blogspot.com.au/2007/10/time-picker-user-control.html)  b. Dipitimaya Patra's datepicker in Datagrid I came up with a modified custom timepicker control embedded in WPF Datagrid with databinding features. I encountered bugs on migrating the present time picker custom control throughout development in .Visual Studio 2010 and I manage to fix them myself. The errors are specifically found on the keydown events and time updates (increment/decrement of values). Here are the things that I did to make this work: 1. I added a dependency property to the user control public DateTime TimeValue { get { return (DateTime)GetValue(TimeProperty); } set { SetValue(TimeProperty, value ); } } public static readonly DependencyProperty TimeProperty = DependencyProperty.Register( "TimeValue" , typeof (DateTime), typeof (TimeControlBinding), new UIPropertyMetadata(D...

Donate