Monday 29 July 2013

Convert List to Datatable in C#

 public DataTable ToDataTable<T>(IList<T> dataList)// T is any generic type
    {
        PropertyDescriptorCollection props = TypeDescriptor.GetProperties(typeof(T));

        DataTable table = new DataTable();
        for (int i = 0; i < props.Count; i++)
        {
            PropertyDescriptor prop = props[i];
            table.Columns.Add(prop.Name, prop.PropertyType);
        }
        object[] values = new object[props.Count];
        foreach (T item in dataList)
        {
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = props[i].GetValue(item);
            }
            table.Rows.Add(values);
        }
        return table;
    }

Wednesday 5 June 2013

Difference between ListView and DataGrid in WPF

1- The difference between ListView and DataGrid is Editing. 
Edit allow in datagrid  but not in ListView. You can also edit in ListView, but it is easy and build in DataGrid.

2-Automatic column generation support in Datagrid only.



<DataGrid Height="200" Width="500" HorizontalAlignment="Left" Margin="12,21,0,0"
  Name="McDataGrid" VerticalAlignment="Top" RowHeight="30" ColumnWidth="100>
</DataGrid>
 


Selection Mode in DataGrid
The SelectionMode property decides if the DataGrid allows only a single row or multiple rows selection. It has two values  Single and Extended.  The following code sets the SelectionMode to Single .
SelectionMode="Single "
 

Scrolling

VerticalScrollBarVisibility="Visible"
HorizontalScrollBarVisibility="Visible"

Read Only
IsReadOnly="True"

All these are the property of Datagrid.  

 

Tuesday 4 June 2013

Tree View in WPF

If you want to create a simple tree View in WPF. Just add TreeView control on your page and add items in either using XAML or from code behind.

 <TreeView>
    <TreeViewItem Header="ASIA">
        <TreeViewItem Header="INDIA"></TreeViewItem>
        <TreeViewItem Header="PAKISTAN"></TreeViewItem>
        <TreeViewItem Header="SRI LANKA"></TreeViewItem>
    </TreeViewItem>
    <TreeViewItem Header="South America">
        <TreeViewItem Header="Argentina"></TreeViewItem>     
        <TreeViewItem Header="Uruguay"></TreeViewItem>
         <TreeViewItem Header="Brazil"></TreeViewItem>
 </TreeViewItem>
 </TreeView>


For more details please Visit.
http://www.c-sharpcorner.com/UploadFile/mahesh/treeview-in-wpf/

Monday 3 June 2013

Introduction to DML, DDL, DCL and TCL –

DDL
DDL (Data Definition Language). It is used to create and modify the structure of database objects in database.

Examples: CREATE, ALTER, DROP Table or database statements.



DML
DML(Data Manipulation Language). It is used to retrieve, store, modify, delete, insert and update data in  table database.

Examples: SELECT, UPDATE, INSERT statements.


TCL
TCL(Transactional Control Language). It is used to manage different transactions occurring within a database.

Examples: COMMIT, ROLLBACK statements.



DCL
DCL(Data Control Language). It is used to create roles, permissions,  to control access to database by securing it.

Examples: GRANT, REVOKE statements



Date Picker in WPF

I currently have a program that takes the value from a datePicker and have the date saved as a string. I only needed the date not the time so i used the following code to save the date value:
DateTime StartDate;
String inMyString;
savedDate = datePicker1.SelectedDate.Value.Date;
inMyString =   savedDate.Date.ToShortDateString()


<DatePicker Height="25" HorizontalAlignment="Left" Margin="42,26,0,0" Name="datePicker1"
            VerticalAlignment="Top" Width="115" />

Saturday 18 May 2013

Filter for file extension.

 // Create OpenFileDialog  on button click Event!
    Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
 

 
    // Set filter for file extension.
   
    dlg.Filter = "EXCEL Files (*.xls)|*.xlsx"
 
   dlg.Filter = "Text Files | *.txt"; 
 
 
dlg .Filter = "png files (*.png)|*.png|
                          jpg files (*.jpg)|*.jpg|
                          jpeg files (*.jpeg)|*.jpeg|
                          gif files (*.gif)|*.gif|
                          Image Files(*.png;*.jpg;*.jpeg;*.gif)|*.png;*.jpg;*.jpeg;*.gif";  

    

Thursday 11 April 2013

How to Refresh Grid Auto........


add this method.

  //Set and start the timer
        private void SetTimer()
        {
            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = new TimeSpan(0, 0, 60);
            dispatcherTimer.Start();
        }

create this Event where you want
 protected void dispatcherTimer_Tick(object sender, EventArgs e)
        {
           btnSearch_Click(null,null);
        }

Tnks

Wednesday 27 March 2013

Layout Controls


Canvas
Lets you position child controls explicitly by specifying the distances
between their left, top, right, and bottom edges and those of the Canvas.

<Canvas>
<Button Content=”TopLeft” Width=”85” Height=”30”
Canvas.Top=”20” Canvas.Left=”20”/>
<Button Content=”TopRight” Width=”85” Height=”30”
Canvas.Top=”20” Canvas.Right=”20”/>
<Button Content=”BottomLeft” Width=”85” Height=”30”
Canvas.Bottom=”20” Canvas.Left=”20”/>
<Button Content=”BottomRight” Width=”85” Height=”30”
Canvas.Bottom=”20” Canvas.Right=”20”/>
</Canvas>

DockPanel Docks its children to its edges.

<DockPanel LastChildFill=”True”>
<Border DockPanel.Dock=”Top” Background=”LightGreen”>
<Label Content=”1, Top”/>
</Border>
<Border DockPanel.Dock=”Left” Background=”#FFFF00FF”>
<Label Content=”2, Left” >
<Label.LayoutTransform>
<RotateTransform Angle=”-90”/>
</Label.LayoutTransform>
</Label>
</Border>
<Border DockPanel.Dock=”Right” Background=”#FFFFB400”>
<Label Content=”3, Right” >
<Label.LayoutTransform>
<RotateTransform Angle=”90”/>
</Label.LayoutTransform>
</Label>
</Border>
<Border DockPanel.Dock=”Bottom” Background=”Yellow”>
<Label Content=”4, Bottom”/>
</Border>
<Border DockPanel.Dock=”Bottom” Background=”#FF80FFFF”>
<Label Content=”5, Bottom”/>
</Border>
<Border Background=”White”>
<Label Content=”6, None”/>
</Border>
</DockPanel>

Expander Displays a header and an icon that the user can click on to show or hide a
single child control.



Grid Displays children in rows and columns. You can also ignore the rows and
columns and position children somewhat as you can in a Canvas.

<Grid Margin=”5”>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=”0.75 in”/>
<ColumnDefinition Width=”2*”/>
<ColumnDefinition Width=”1*”/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height=”30”/>
<RowDefinition Height=”*”/>
</Grid.RowDefinitions>
</Grid>

Thursday 21 February 2013

Content Controls


Content Controls are mainly parent containers to hold the content. It displays information to the user to be viewed but that generally won't be modified.
It has three main points.
1-Property--->A Property specifies the behavior of object's and  appearance . 
 example,  IsEnabled property 

2-Method--->A method is a code block containing a series of statements
example  CountMethod(), counts the number of items


3-Event--->An event is related when a control raises  that something has to happened. 
 example TextChanged event .


<Label Content="Name Name="lblEmployeeName" Height="25" width="100" />
<Button Name="btnCount" Content="Count" Click="btnCount_Click" /> 

ToolTip: Displays a tooltip for another object. 
 
<TextBox  Name="txtEmployeeName" Text="" ToolTip="Employee name" />

<Border HorizontalAlignment="Center" VerticalAlignment="Center" Width="200"Height="200" BorderThickness="2">



 

Unicode Vs ASCII


Unicode used 16 bit number to store information about Charater & symbols, whereas ascii used 8 bit. thus Unicode can represent more than 65000 characters/symbols as compared to ASCII only 256 characters. Unicode charqacters are standardized to represent most of commonly used languages worldwide including asian/indian languages. This is helping in common standard for document genration in any language independent of any custom software using custom mapping of characters. You can read E-mail message world wide , read message i

Types of controls in WPF

WPF provides total three types of controls.
  1. Content Controls
  2. Item Controls
  3. Layout Controls