<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar/19834389?origin\x3dhttp://netchallenges.blogspot.com', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe" }); } }); </script>

Put some text here ...

Put some text here ...

Put some text here ...

Put some text here ...

Put some text here ...

Put some text here ...

Saturday, April 29, 2006

Enhanced TreeView Control for Windows Apps






Problem: I need to present summarized data along with controls categorically arranged in some in some kind of a hierarchy. A simple TreeView control allows displaying of small bit of information per node. I needed a TreeView control that allows more complex type of information to be arranged under a tree.

Solution:
An Enhanced TreeView control [click on the screen shots to check it out]. I did not have much time to spend on this, and I havnt really used it yet. The look n' feel of the control is completely customizable. If you find any use for it, then go ahead download it! If you are unable to download it, you may contact me, and I'll send it over to you (FREE ofcourse).

The source code will be shortly released under GNU license. Everyone is encouraged to use, extend, and polish the functionality of the control.

------------TO USE THE CONTROL---------------
The control in the first screen shots was created by the following code:
etv1 = New EnhancedTreeView
'Set Look n' Feel for the EnhancedTreeView control
Me.etv1.AutoScroll = True
Me.etv1.BackColor = System.Drawing.Color.Transparent
Me.etv1.Font = New System.Drawing.Font("Tahoma", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.etv1.Location = New System.Drawing.Point(1, 2)
Me.etv1.Name = "etv1"
Me.etv1.NodeEndColor = System.Drawing.Color.White
Me.etv1.NodeHeight = 20
Me.etv1.NodeStartColor = System.Drawing.Color.Lavender
Me.etv1.NoteLabel = Nothing
Me.etv1.Size = New System.Drawing.Size(512, 372)
Me.etv1.TabIndex = 1

'Build Node list
Me.etv1.NodeList.Add("Root 1")
Me.etv1.NodeList(0).TitleNote = Date.Now.ToShortDateString
Me.etv1.NodeList.Add("Root 2")
Me.etv1.NodeList(1).TitleNote = "By Nomair Kashif"
Me.etv1.NodeList(0).ShowPlus = True
Me.etv1.NodeList(1).ShowPlus = True
Me.etv1.NodeList(0).DetailPanelHeight = 190
Me.etv1.NodeList(0).NodeDetailsPanel.Controls.Add(New MonthCalendar)
Me.etv1.NodeList(1).ChildNodes.Add("Root2 - Child 1")
Me.etv1.NodeList(1).ChildNodes.Add("Root 2- Child 2")
Me.etv1.NodeList(1).ChildNodes(0).ShowPlus = True
Me.etv1.NodeList(1).ChildNodes(1).ShowPlus = True
Me.Controls.Add(etv1)

{END}

Thursday, April 27, 2006

DataView Row Filter Based On Pattern Matching Column(s)

Tested On:
VS Version: 2002 and 2003
.NET Frakework Version 1.1 and 1.0


Problem:
I am trying to filter a set of records retreived from the database based on altering portions of a single column.

For Example: Consider a column, ItemNo to contain values such as C141XX00220052CGVK. The 18 character Item No. consists of diferent meaningful coded parts (as in the figure above).

We have:
1) One column storing ItemNo as varchar (SQL Server 2000)
2) A need to flexibly search and filter records as if each part of the item number were in its own column.

Solution 1:
Use T-SQL LIKE clause.
Problem: LIKE clause does not allows wildcards in the middle of the string. For example:

*C14* - is valid

C34* - is valid

*C4*K4* - is invalid

My Solution:
1) Construct a RegEx regular expression based on the pattern of values (item no. parts) supplied
2)Traverse the DataRowViewCollection of the Defaul DataView object
3)Use RegExp.IsMatch() method to compare the (ItemNo) column value with the regular expression for each DataRow object in the collection
4)Mark rows for delete
5) Delete row(s)

[Source Code Below]

'Simply call doDeepFilter function with column name, and regular expression to match. Then bind the DataView/DataSet object to any data live control.
Me.doDeepFilter("itemNo", getFilterQuery())
rptProductionList.DataSource = dvList
rptProductionList.DataBind()
---------------------------------------------------
Private Sub doDeepFilter(ByVal colName As String, ByVal regExp As String)
Dim deleteArray As New ArrayList
If Me.advanceSearchPanel.Visible Then
For i As Integer = 0 To dvList.Count - 1
If Regex.IsMatch(CType(dvList.Item(i).Row.Item(colName), String), regExp) = False Then
deleteArray.Add(dvList.Item(i).Row)
End If
Next
End If

For Each dr As DataRow In deleteArray
dr.Delete()
Next
End Sub
------------------------------------------------------------------------------------
Private Function getFilterQuery() As String
Dim searchExpression As String
searchExpression = searchExpression.Concat(searchExpression, ParseItemNoToExpression(Me.txtitemConductor.MaxLength, Me.txtitemConductor.Text.ToUpper))
searchExpression = searchExpression.Concat(searchExpression, ParseItemNoToExpression(Me.txtBuild.MaxLength, Me.txtBuild.Text.ToUpper))
searchExpression = searchExpression.Concat(searchExpression, ParseItemNoToExpression(Me.txtFilm.MaxLength, Me.txtFilm.Text.ToUpper))
searchExpression = searchExpression.Concat(searchExpression, ParseItemNoToExpression(Me.txtSize.MaxLength, Me.txtSize.Text.ToUpper))
searchExpression = searchExpression.Concat(searchExpression, ParseItemNoToExpression(Me.txtPackaging.MaxLength, Me.txtPackaging.Text.ToUpper))
searchExpression = searchExpression.Concat(searchExpression, ParseItemNoToExpression(Me.txtClass.MaxLength, Me.txtClass.Text.ToUpper))
searchExpression = searchExpression.Concat(searchExpression, ParseItemNoToExpression(Me.txtCustomer.MaxLength, Me.txtCustomer.Text.ToUpper))
Return "\b" & searchExpression & "\b"
End Function
--------------------CREATE A REGULAR EXPRESSION DYNAMICALLY--------------
Private Function ParseItemNoToExpression(ByVal characters As Integer, ByVal str As String) As String
Dim strBuilder As New StringBuilder
If str.Length = 0 Then
Return strBuilder.Append("\").Append("w{").Append(characters & "}".Chars(0)).ToString
ElseIf str.Length > 0 And str.Length < style="color: rgb(0, 0, 153);">Then

For Each chr As Char In str
strBuilder.Append("[" & chr & "]")
Next
Return strBuilder.Append("\").Append("w").Append("{" & characters - str.Length & "}".Chars(0)).ToString
Else
Return "[" & str & "]" 'return pattern in regular expression
End If
End Function