Thursday, January 25, 2007

VS templates not working? Easy to get things back.

Recently I had to work with window SharePoint Service 3.0 and its development. I download the visual studio 2005 project templates for SharePoint development. I downloaded the project msi from Microsoft download site.

http://download.microsoft.com/download/e/8/a/e8aa8476-5af6-4f38-aed2-0247a99d2bc6/VSeWSS.msi

Installed in my local computer… but when I opened the IDE2005 project templates are not there…..

I got confused… and try reinstall the msi… but noting happed… I went to google and found few people is also suffering from this problem… the problem is my vs2005 is installed in different drive other that “c:\” and the installed temples are in default “c:\”… and then I moved my template in the drive where the IDE2005 is installed….

Location of the project templates is [your dive letter]:\Program Files\Microsoft Visual Studio 8\Common7\IDE…

There were two directories one if project template and other is item template… last thing that I did is to make ide identity the project templates….

For this I had to just a command in vs2005 comma prompt..

devenv /installvstemplates

I found help from the following forum… please go there for more detailed discussion…

http://geekswithblogs.net/ehammersley/archive/2005/11/08/59451.aspx

Hope this will help someone someday….

Friday, January 5, 2007

Bubble Sort

Introduction

Bubble sort, also known as sinking sort, is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted, comparing each pair of adjacent items and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Because it only uses comparisons to operate on elements, it is a comparison sort. Although the algorithm is simple, it is not efficient for sorting large lists; other algorithms are better.

Pseudo Code

The pseudo code of the bubble sort is given bellow.

procedure bubbleSort( A : list of sortable items )
repeat
swapped = false
for i = 1 to length(A) - 1 inclusive do:
if A[i-1] > A[i] then
swap( A[i-1], A[i] )
swapped = true
end if
end for
until not swapped
end procedure


Complexity


Bubble sort has worst-case and average complexity both О(n2), where n is the number of items being sorted. There exist many sorting algorithms with substantially better worst-case or average complexity of O(n log n). Even other О(n2) sorting algorithms, such as insertion sort, tend to have better performance than bubble sort. Therefore, bubble sort is not a practical sorting algorithm when n is large.


The only significant advantage that bubble sort has over most other implementations, even quicksort, but not insertion sort, is that the ability to detect that the list is sorted is efficiently built into the algorithm. Performance of bubble sort over an already-sorted list (best-case) is O(n). By contrast, most other algorithms, even those with better average-case complexity, perform their entire sorting process on the set and thus are more complex. However, not only does insertion sort have this mechanism too, but it also performs better on a list that is substantially sorted (having a small number of inversions).


Simulation


Simulation #1:


image


Video


 


More online simulation



Implementation


Implementations of the bubble sort is given bellow. For now we have only three supported language, in future we would try to incorporate more implementations.


Code Sample in “c”


Real implementation in c is given bellow.


#include<stdio.h>  
#include<conio.h>

void bubble(int a[],int n)
{
int i,j,t;
for(i=n-2;i>=0;i--)
{
for(j=0;j<=i;j++)

{
if(a[j]>a[j+1])
{
t=a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}


}//end for 1.

}//end function.


void main()
{
int a[100],n,i;

clrscr();

printf("\n\n Enter integer value for total no.s of elements to be sorted: ");
scanf("%d",&n);

for( i=0;i<=n-1;i++)
{ printf("\n\n Enter integer value for element no.%d : ",i+1);
scanf("%d",&a[i]);
}

bubble(a,n);

printf("\n\n Finally sorted array is: ");
for( i=0;i<=n-1;i++)
printf("%3d",a[i]);

} //end program.


Code Sample in “c++”


Bellow a simple implementation of bubble sort in c++ is given.


#include <stdio.h>
#include <iostream.h>

void bubbleSort(int *array,int length)//Bubble sort function
{
int i,j;
for(i=0;i<10;i++)
{
for(j=0;j<i;j++)
{
if(array[i]>array[j])
{
int temp=array[i]; //swap
array[i]=array[j];
array[j]=temp;
}
}
}
}

void printElements(int *array,int length) //print array elements
{
int i=0;
for(i=0;i<10;i++)
cout<<array[i]<<endl;
}


void main()
{
int a[]={9,6,5,23,2,6,2,7,1,8}; // array to sort
bubbleSort(a,10); //call to bubble sort
printElements(a,10); // print elements
}


Code Sample in “c#”


The c# implementation is given bellow.


namespace AllAlgorithm
{
public class BubbleSort
{
private readonly int[] _samples = new int[100];
private int x;
public void SortArray()
{
int i;
int j;
for (i = (x - 1); i >= 0; i--)
{
for (j = 1; j <= i; j++)
{
if (_samples[j - 1] > _samples[j])
{
int temp = _samples[j - 1];
_samples[j - 1] = _samples[j];
_samples[j] = temp;
}
}
}
}
}
}


References



  1. http://en.wikipedia.org/wiki/Bubble_sort
  2. http://www.sorting-algorithms.com/bubble-sort
  3. http://www.sorting-algorithms.com/

Friday, December 8, 2006

Implementing Xceed GroupRow and Enabling Row Grouping

Xceed Grid of 3.x Version has a very interesting feature Called Grouping. It allows you to show rows in groups and in a horizontal tree structure. Now let’s discuss about how to implement Xceed grid group feature. Well Xceed grouping feature works on columns that is you must group the rows on a particular column, but you can also use recursive grouping.

To add grouping feature first you need to add a Group Object. And we need to set the property “GroupBy”. “GroupBy” property of Group object takes a string as value which represents a column name of the grid. Bellow in code we have a simple example how to add a group by row.

private Xceed.Grid.Group group;

//in declaration section

//in initialization section

grid.Columns.Add( new Column( "DEPT", typeof( string ) ) );

grid.Columns["DEPT "].Title = "Department";

grid.Columns.Add( new Column( "NAME", typeof( string ) ) );

grid.Columns["NAME"].Title = "Employee Name";

group = new Group();

group.GroupBy = "DEPT";

grid.GroupTemplates.Add( group );

grid.UpdateGrouping();

In the above example we have two column name and department. And we want to group employees by department. So groupby property of group object is set to the column name. And last of all you need to add the group object in the grid’s group template and call the update grouping method of the grid to activate the grouping.

Xceed by default adds a group header row. But we can always customize the group header and add our own customized group row. Bellow a simple example is given how to add group header row.

//in declaration section

private Xceed.Grid.GroupManagerRow gmrow;

//in initialization section

gmrow = new GroupManagerRow();

gmrow.Height = 24;

group.HeaderRows.Add( gmrow );

Xceed have GroupMangerRow for this purpose. You must add the GroupMangerRow to the header collection of the group object. And you can customize its Font, Fore Color, Title Format, Back Color, and other properties. Title format is very interesting. By default GroupMangerRow show the assigned groupby row column Title. But we can customize the Group by Header Row Title.

gmrow.TitleFormat = "%GROUPKEY% have %DATAROWCOUNT% Employees";

Here I have used only two keys to customize the Title format of the group header row. Please go to your Xceed Grid help and look for GroupManagerRow.TitleFormat property and look for more interesting feature to customized the group header row title.  

Sunday, November 26, 2006

Asp.net Tree view control, very useful But.

Asp.net 2.0 ships with a whole new set of controls. Navigation controls are one of them. In navigation control we have three options

  1. Sitemap path
  2. Menu
  3. Tree View

TreeView

 

Recently I have worked in a project which is a demo project where I had the pleasure of using the asp.net 2.0 tree view control. Below I will be demonstrating a simple way to use the treeview and some things that we should know while we use tree view control of asp.net 2.0 in our projects.

 

Obviously tree view control has node property and nodes can be create dynamically and modify the node collection on runtime. But it’s for only level one node. For level two nodes node is created just the way it is, but need to add in the child node property. So in a sense tree view has node property and nodes have no recursive node property and to deal with child node, node has child node collection.

 

Constructor of Node class has several overloads. Actually 5 of them are there.

 

TreeNode tn = new TreeNode("Text");

TreeNode tn = new TreeNode("Text", _value);

 

Here we should always be careful about the value property. This value property must be distinct for each collection.

 

For example if we have a Tree Node consists of three Nodes and each and every done has value property as a same value. SelectedNodeChanged even returns always the first node of the collection.

 

TreeNode tn1 = new TreeNode("Node One",-1);

TreeNode tn2 = new TreeNode("Node Two",-1);

TreeNode tn3 = new TreeNode("Node Three",-1);

TreeView1.Nodes.Add(tn1);

TreeView1.Nodes.Add(tn2);

TreeView1.Nodes.Add(tn3);

 

In the web application if we select node three that is tn3 … in SelectedNodeChanged event we will have th1 as SelectedNode. I don’t know how this happened but surely it happened. But if we provide different value in the value field of the node constructor this was okay. Even if we don’t provide any value things work just fine.

 

Tree view has a wide range of configuration and style settings. Among these StaticItemStyle and StaticItemHoverStyle is most useful.

 

Well sometime we need to disable a node in our view. But TreeNode class do not have any enable or disable property, rather it has selection Action Property. We need to set the selection property value to none to make a node disabled.

Thursday, October 12, 2006

Xceed Grid Check box Column and Single Click Edit

In some cases we need to put a column with check box, so that we can select some row with check box. And then perform some operation depending on check box value. Xceed provide a very simple and easy way to accomplish this task. All you need to do is to add a column and set is data type to bool that’s it you are done.

XceedGridWithChekbox

grid.Columns.Add( new Column( "CHECKBOX", typeof( bool ) ) );

grid.Columns["CHECKBOX"].Title = "";

grid.Columns["CHECKBOX"].Width = 100;

grid.Columns["CHECKBOX"].Fixed = true;//XceedGrid 3.1

 

Now how do you set or get checked state from the column. Well when creating a new data row you simple put true or false to the value of the cell. If you assign false the checkbox will be unchecked and vice versa.

 

//setting values

Xceed.Grid.DataRow row = this.grid.DataRows.AddNew();

row.Cells["CHECKBOX"].Value = false;

foreach(DataRow row in grid.DataRows)

if((bool)row.Cells["CHECKBOX"].Value == true)

{

//do some work

}

Wednesday, October 11, 2006

Working with Xceed Cell Editor

In version 3.1 Xceed provided lot of interesting stuff and one of them is Xceed editors. Some most interesting Xceed editors are

Win Combo box
Option Picker

Let get started with how to define a custom cell editor. Let say we have one column that provide description of a data and the column is a multi line supported column. And we want to have custom editor for the description.

First we need to define a cell editor control, for this case this will be a text area, which is a textbox with multiline property set to true. some other property of the textbox also need to set to true for instance AcceptsReturn and WordWrap

//declaration sectionprivate TextBox cellEditorTextBox;

//initialize component

sectioncellEditorTextBox = new TextBox();

cellEditorTextBox.Multiline = true;

cellEditorTextBox.WordWrap = true;

cellEditorTextBox.AcceptsReturn = true;

cellEditorTextBox.Width = 200;cellEditorTextBox.Height = 100;

Now we need to assign the control to the column editor so that when a cell for a column is enter in
edit mode our control can be used to edit the cell. Xcced provide two manager class to deal with cell view and cell edit.
those are

CellEditorManagerCellViewerManager

//assuming that we have have a column named Description
Description.CellEditorManager = new CellEditorManager(cellEditorTextBox,"Text",false,true);

Parameters of CellEditorManager

templateControl
A reference to a Control representing the control that will be used as a template to create the controls that will edit the content of cells.

propertyName
A string representing the property used to get the control's value.
inPlace
true if the Control is painted within the bounds of the cell; false otherwise.

handleActivationClick
Indicates if the control should handle the mouse click once it is activated. Only in the case where inPlace is set to true does it make sense for handleActivationClick to also be set to true.

Defining a WinComboBox

So now we know how to deal with the custom cell editor. may be in some case we need to use a combo box in a xcced data grid to select a value for the cell. we can use custom cell editor for solving the purpose. Some issue need to consider before you actually do the implementation. Case one can be whither all your row need same set of value in the combo box or in case two you need to populate different set of items in the combo box when user enters in edit mode.

If you need only one set then initialize the combo box before assigning to the cell editor manager or if you need different set then you need to subscribe the event of a cell EnteringEdit in the entering edit you can repopulate any item collection you want.

//assuming that we have a column named Name and a win combo box named

//wincombo1private

WinComboBox  NameGridCombo = new WinComboBox();

grid.Columns["Name"].CellEditorManager = new ComboBoxEditor (wincombo1);

Configure row to show Multi line Data

well xceed do support multi line data in there cell for this we need to set some properties of the cell, but one thing must be considered if you have assigned a fixed height to a xceed row this will not work.

//three property must be set for this

Grid.DataRowTemplate.AutoHeightMode = AutoHeightMode.AllContent;

Grid.DataRowTemplate.WordWrap = true;

Grid.DataRowTemplate.FitHeightToEditors = true;