Thursday, March 1, 2018

Alfaaz

Tu Rooh to mai teri kaya banu,
taumr mai tera saya banu,
Keh de to ban jaun bairaag mai,
keh do to mai teri maya banu,

tu saaz hai, mai ragini,
tu raat hai, mai chandani....

Guitar Chord : Dil ko tumse pyaar hua # RHTDM

Dil ko tumse pyaar hua - RHTDM

  Am    Dm       G
Dil ko tumse pyaar hua
   C        F    G      C     E
pehli baar hua tumse pyaar hua
  Am       Dm      G
main bhi aashiq yaar hua 
   C       F     G       C    E
pehli baar hua tumse pyaar hua
   Dm    Am
chayi hai.....
   Dm    Am
beataabi......
   Bb          F         E
meri jaan kaho main kya karoon

           Am
Kho gaya main khyalon main,
           Am
Ab neend bhi nahi aankhon main.
           Am
Karwate was badalta hoon,
           Am
Ab jaagta hoon main raaton main.
Am       G        F         C      E
ab doori na sahni har lamha kehta hai
   Am    G         F         C      E
na jaane haal mera aisa kyun rehta hai
       Am                Am                      Am
hasina gori gori churaye chori chori churaye dil chori chori chori chori

Guitar Chord : Jo Bhi Main # Rockstar

JO BHi Main... Chords....

(Em)Jo bhi main... (Em)Kehna chahoon
(G)Barbad kare.. (Em)Alfaaz mere... Alfaaz mere

(Em)O ya ya…
(D)Ya ya ya
(Em)Ya ha hm…
(D)O o o

(G)Kabhi mujhe Lage ki jaise,
(D)Sara hi yeh jahan hai jaadu,
(Am)Jo hai bhi aur Nahi bhi hai yeh..... (D) Fiza, Ghata, Hawa, Baharein

(G)Mujhe..Kare.. (D)Ishare yeh..
(Am)Kaise..Kahoon....
(D)Kahani main innki

(Em)Jo bhi main.....(Em)Kehna chahoon
(G)Barbad kare... (Em)Alfaaz mere...Alfaaz mere
O ya ya..
O ya ya ya 

Tuesday, August 12, 2014

How to add TreeViewItem dynamically in TreeView control in WPF?

How to add TreeViewItem dynamically in TreeView control in WPF. Here is the coding example given below to add TreeViewItem in TreeView control.


public TreeViewItem CreateTreeViewItem(string nodeName, string headerText, string frontImagePath, string tailImagePath, bool isCheckBoxRequired)
        {
            TreeViewItem treeViewItem = new TreeViewItem();
            try
            {
                StackPanel stackPanel = new StackPanel();
                Label lblHeaderText = new Label();
                Image imgFrontIcon, imgTailIcon;
                imgFrontIcon = new Image(); imgTailIcon = new Image();

                stackPanel.Orientation = Orientation.Horizontal;
                if (isCheckBoxRequired)
                {
                    CheckBox chkbox = new CheckBox();
                    chkbox.Name = IDPrefixForControls.Chk_.ToString() + nodeName;
                    chkbox.HorizontalAlignment = HorizontalAlignment.Center;
                    chkbox.VerticalAlignment = VerticalAlignment.Center;
                    stackPanel.Children.Add(chkbox);
                }
                if (frontImagePath != null && frontImagePath != string.Empty)
                {
                    Uri uri = new Uri(ConstantVariables.UriString + frontImagePath);
                    BitmapImage bitMapSource = new BitmapImage();
                    bitMapSource.BeginInit();
                    bitMapSource.UriSource = uri;
                    bitMapSource.EndInit();
                    imgFrontIcon.Source = bitMapSource;
                }
                if (tailImagePath != null && tailImagePath != string.Empty)
                {
                    Uri uri = new Uri(ConstantVariables.UriString + tailImagePath);
                    BitmapImage bitMapSource = new BitmapImage();
                    bitMapSource.BeginInit();
                    bitMapSource.UriSource = uri;
                    bitMapSource.EndInit();
                    imgTailIcon.Source = bitMapSource;
                }
                lblHeaderText.Content = headerText;
                stackPanel.Children.Add(imgFrontIcon);
                stackPanel.Children.Add(lblHeaderText);
                stackPanel.Children.Add(imgTailIcon);
                nodeName = nodeName.Replace("-", "_").Replace(" ", "_");
                treeViewItem.Name = nodeName;
                treeViewItem.Header = stackPanel;
            }
            catch (Exception ex)
            { LogExceptionDetails(ex); }
            return treeViewItem;
        }

Add Image column in Datagrid control dynamically in WPF

Here is the code example given to add Image column in Datagrid control dynamically at run time in WPF.

public void AddColumnsToDataGrid(DataGrid dataGrid, DataGridColumnType columnType, string headerText, string bindingName, string imagePath,
           )
        {
FrameworkElementFactory factoryElementStackPanelImages = AddMultipleImagesIntoOneColumn(imagePath);
                            DataTemplate dataTemplate = new DataTemplate();
                            dataTemplate.VisualTree = factoryElementStackPanelImages;

                            DataGridTemplateColumn dgTemplateColumn = new DataGridTemplateColumn();
                            dgTemplateColumn.Header = headerText;
                            dgTemplateColumn.CellTemplate = dataTemplate;
                            dgTemplateColumn.CellStyle = styleDataGridCell;
                            dataGrid.Columns.Add(dgTemplateColumn);
}

private FrameworkElementFactory AddMultipleImagesIntoOneColumn(string imagesSourcePath)
        {
            FrameworkElementFactory factoryElementStackPanel = new FrameworkElementFactory(typeof(StackPanel));
            try
            {
                string imagePath, imageName;
                factoryElementStackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
                FrameworkElementFactory factoryImage;
                if (imagesSourcePath.Contains(ConstantVariables.CharacterValueHash))
                {
                    string[] arrImageSource = imagesSourcePath.Split(Convert.ToChar(ConstantVariables.CharacterValueHash));
                    foreach (string imgSource in arrImageSource)
                    {
                        if (imgSource.Contains(ConstantVariables.CharacterValueDollar))
                        {
                            string[] arrImagePathNName = imgSource.Split(Convert.ToChar(ConstantVariables.CharacterValueDollar));
                            imagePath = arrImagePathNName[0];
                            imageName = arrImagePathNName[1];
                        }
                        else
                        {
                            imagePath = imgSource;
                            imageName = string.Empty;
                        }
                        Uri uri = new Uri(ConstantVariables.UriString + imagePath);
                        BitmapImage bitMapSource = new BitmapImage();
                        bitMapSource.BeginInit();
                        bitMapSource.UriSource = uri;
                        bitMapSource.EndInit();
                        factoryImage = new FrameworkElementFactory(typeof(Image));
                        factoryImage.SetValue(Image.SourceProperty, bitMapSource);
                        factoryImage.SetValue(Image.WidthProperty, 15d);
                        factoryImage.SetValue(Image.HeightProperty, 15d);
                        factoryImage.SetValue(Image.MarginProperty, new Thickness(1));
                        if (!imageName.Equals(string.Empty))
                        {
                            factoryImage.SetValue(Image.NameProperty, imageName);
                            factoryImage.SetValue(Image.ToolTipProperty, imageName);
                        }
                        factoryElementStackPanel.AppendChild(factoryImage);
                        ImageColumnElement.Add(factoryImage);
                    }
                }
                else
                {
                    if (imagesSourcePath.Contains(ConstantVariables.CharacterValueDollar))
                    {
                        string[] arrImagePathNName = imagesSourcePath.Split(Convert.ToChar(ConstantVariables.CharacterValueDollar));
                        imagePath = arrImagePathNName[0];
                        imageName = arrImagePathNName[1];
                    }
                    else
                    {
                        imagePath = imagesSourcePath;
                        imageName = string.Empty;
                    }
                    Uri uri = new Uri(ConstantVariables.UriString + imagePath);
                    BitmapImage bitMapSource = new BitmapImage();
                    bitMapSource.BeginInit();
                    bitMapSource.UriSource = uri;
                    bitMapSource.EndInit();
                    factoryImage = new FrameworkElementFactory(typeof(Image));
                    factoryImage.SetValue(Image.SourceProperty, bitMapSource);
                    factoryImage.SetValue(Image.WidthProperty, 15d);
                    factoryImage.SetValue(Image.HeightProperty, 15d);
                    factoryImage.SetValue(Image.MarginProperty, new Thickness(1));

                    if (!imageName.Equals(string.Empty))
                    {
                        factoryImage.SetValue(Image.NameProperty, imageName);
                        factoryImage.SetValue(Image.ToolTipProperty, imageName);
                    }
                    factoryElementStackPanel.AppendChild(factoryImage);
                    ImageColumnElement.Add(factoryImage);
                }
            }
            catch (Exception ex)
            { LogExceptionDetails(ex); }
            return factoryElementStackPanel;
        }


Adding of Checkbox Column in Datagrid control in WPF

Some times we need to add some controls in a container at run time. Here is the coding logic given to add CheckBox column in Datagrid control dynamically at run time. This code logic is in context with WPF. for winforms the some classes may differ.

Example :

DataGridTemplateColumn dgTemplateColumn = new DataGridTemplateColumn();
                            
                            dgTemplateColumn.Header = headerText;

                            FrameworkElementFactory factoryElementCheckBox = new FrameworkElementFactory(typeof(CheckBox));
                            factoryElementCheckBox.SetBinding(CheckBox.IsCheckedProperty, new System.Windows.Data.Binding(bindingName));
                            factoryElementCheckBox.SetValue(CheckBox.NameProperty, bindingName);
                            factoryElementCheckBox.SetValue(CheckBox.HorizontalAlignmentProperty, HorizontalAlignment.Left);
                            factoryElementCheckBox.SetValue(CheckBox.VerticalAlignmentProperty, VerticalAlignment.Center);

                            CheckBoxColumnElement.Add(factoryElementCheckBox);

                            DataTemplate dataTemplate = new DataTemplate();
                            dataTemplate.VisualTree = factoryElementCheckBox;
                            dgTemplateColumn.CellTemplate = dataTemplate;
                            dgTemplateColumn.IsReadOnly = isReadOnly;
                            dataGrid.Columns.Add(dgTemplateColumn);
                            

Wednesday, July 30, 2014

Why to use an Interface?

While doing object oriented programming we generally make the classes and provide the functionality in it to give to the outside world.

That class may contain some private members and methods and some public members, properties and methods to use the functionality. While accessing the class members and methods we create object of the class and initialize it to call the methods.

This is the very basic development approach. We generally tend to ignore the usage and importance of Interface. An interface can provide us the flexibility of better utilization of memory and structure declaration for the members of the class. Also at the same time we can better use the concept of object oriented programming.

By use of an interface to implement over the class we can achieve the followings
è Encapsulation
è Polymorphism
è Better usage of memory
Here is the list of objects which are available to outside world by using of an interface
è Public properties
è Public methods
è Events
è Indexers
For example :

Public interface IMyFunctions
{
public string inputValue{get;set;}
     Void DoSomething();
}

Class MyFunctions : IMyFunctions
{
public string inputValue{get;set;}
     public Void DoSomething()
{ // provide your logic here }

}

Class OutputClass
{
IMyFunctions myFunctions = new MyFunctions();
myFunctions.inputValue = “TestData”;
muFunctions.DoSomething();
}


Since C#.Net does not support multiple inheritances of the classes, so somehow by using implementing multiple interfaces on a single class we can achieve the same.

Motivational qoutes

पूरे विश्वास के साथ अपने सपनों की तरफ बढ़ें। वही ज़िन्दगी जियें जिसकी कल्पना आपने की है।