Search This Blog

Wednesday, January 16, 2013

Disable ContextMenu RadGridView Telerik

Telerik > Windows Forms > Disable ContextMenu RadGridView

AllowColumnHeaderContextMenu: Gets or sets a value indicating whether context menu is displayed when user right clicks on a data cell.
AllowCellContextMenu: Gets or sets a value indicating whether context menu is displayed when user right clicks on a data cell.

Example: Disable ContextMenu RadGridView Telerik

RadGridView1.MasterTemplate.AllowColumnHeaderContextMenu = False
RadGridView1.MasterTemplate.AllowCellContextMenu = False





WPF CheckBox Control (C#)

CheckBox enables the user to select whether an option is on or off.

XAML:


<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <CheckBox Content="CheckBox" Height="16" HorizontalAlignment="Left" Margin="10,10,0,0" Name="checkBox1" VerticalAlignment="Top" Checked="checkBox1_Checked" Unchecked="checkBox1_Unchecked" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="12,32,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
    </Grid>
</Window>

C# code behind:


 private void checkBox1_Checked(object sender, RoutedEventArgs e)
        {
                MessageBox.Show("checkBox1 Checked");
        }
        private void checkBox1_Unchecked(object sender, RoutedEventArgs e)
        {
              MessageBox.Show("checkBox1 UnChecked");
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (checkBox1.IsChecked == true)
                MessageBox.Show("checkBox1 Checked");
            else
                MessageBox.Show("checkBox1 UnChecked");
        }

Runtime:


WPF Btutton (C#)

This control is designed to be clicked to enable the user to make a choice, to close a dialog box, or to perform another action.

XAML

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
    </Grid>
</Window>

// c# code behind 

private void button1_Click(object sender, RoutedEventArgs e)
{
   MessageBox.Show("Button1 Click"); 
}


Runtime:




Home Next: CheckBox Control

Introduction to Microsoft Windows Applications with WPF (C#)

The user interface (UI) is the visual representation of your application.






A well UI design that flows logically can provide a consistent user experience from application to application and make learning new applications easy for users.

Windows Forms historically has been the basis for most Microsoft Windows applications and can be configured to provide a variety of user interface  options.






WPF is the successor to Windows Forms for desktop application development. WPF applications differ from traditional Windows Forms applications in several ways, the most important is that the code for the user interface is separate from the code for application functionality.
 
Windows Presentation Foundation (WPF) is a next-generation presentation system for building Windows client applications with visually stunning user experiences.

The core of WPF is a resolution-independent and vector-based rendering engine that is built to take advantage of modern graphics hardware. WPF extends the core with a comprehensive set of application-development features that include Extensible Application Markup Language (XAML), controls, data binding, layout3-D graphics, animation,  media, text, etc.

WPF individual controls





These controls have a single purpose in an application; buttons are clicked, text boxes receive and display text, etc.
WPF items controls
Are designed to contain groups of related items: Menu, ListBox, TreeView.
WPF Layout controls
 
Contain multiple nested controls of any type and provide built-in logic for the visual layout of those controls: Grid, StackPanel, Canvas
 

WPF Content Controls

A ontent control derives from the  ContentControl class and can contain a single nested element.
This nested element can be of any type and can be set or retrieved in code through theContent
property.

 


Create Microsoft Windows Applications with WPF (C#)

 
Start Microsoft Visual Studio and from Menu->File select WPF Application


 













For an empty application the XAML contains:
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
    </Grid>
</Window>
 
Grid defines a flexible grid area that consists of columns and rows.
 
Label and TextBox control

Label It is  container for content
<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Label Name="label1">Label control</Label>
    </Grid>
</Window>

Press F5, result is:


 

Labels containsupport for mnemonic keys  when the Alt key is pressed with the mnemonic key.














The mnemonic key is specified by preceding the desired key with the underscore (_) symbol
 

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Label Content="_Code" Target="{Binding ElementName=TextBox1}"></Label>
        <TextBox Name="TextBox1" Margin="65,1,94,287"> </TextBox>
    </Grid>
</Window>

 

 

Next: ButtonControl

Tuesday, January 15, 2013

Set font to RadPrintDocument Telerik (VB.NET)

Telerik > Windows Forms > Set font to RadPrintDocument

Example:

Dim RadPrintDocument1 As New RadPrintDocument
RadPrintDocument1.AssociatedObject = Me.RadGridView1
RadPrintDocument1.HeaderFont = New Drawing.Font("Tahoma", 18, FontStyle.Bold)
RadPrintDocument1.MiddleHeader = "Title"






Set time RadTimePicker Telerik (Windows Forms)

Telerik > Windows Forms > Set time RadTimePicker 

Example:

radTimePicker1.Value = DateTime.ParseExact("13:56", "HH:mm", null);






using Statement (C#)

C# > Statements > using

Defines a scope, outside of which an object or object will be disposed.
The using statement allows the programmer to specify when objects that use resources should release them.

Example

using (SqlConnection connection = new SqlConnection(connectionString))
{
   connection.Open();
}





Set Landscape to PrintPreviewDialog C#

C# > PrintPreviewDialog > LandScape

C# Code


PrintPreviewDialog dialog = new PrintPreviewDialog();
dialog.Document.DefaultPageSettings.Landscape = true;
dialog.ShowDialog();
 
VB.NET
Dim dialog As New PrintPreviewDialog
Dim RadPrintDocument1 As New RadPrintDocument
RadPrintDocument1.AssociatedObject = Me.Grid
dialog.Document = RadPrintDocument1
dialog.Document.DefaultPageSettings.Landscape = True
dialog.ShowDialog()





Monday, January 14, 2013

Delete rows with GridViewCommandColumn RadGridView C#

Telerik > Windows Forms > Delete Row RadGridView


Example: Add GridViewCommandColumn buton to RadGridView to delete current row
GridViewCommandColumn displays a button element.






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls.UI;

namespace WindowsFormsApplication1
{
  public partial class Form1 : Form
 {
    public Form1()
   {
      InitializeComponent();
   }

   private void Form1_Load(object sender, EventArgs e)
  {
   // define text column
    GridViewTextBoxColumn colText = new GridViewTextBoxColumn();
  // define command colum
    GridViewCommandColumn colBtnDelete = new GridViewCommandColumn();
    colBtnDelete.DefaultText = "Delete";
    colBtnDelete.HeaderText = "Delete";
    colBtnDelete.Name = "Delete";
    colBtnDelete.TextAlignment = System.Drawing.ContentAlignment.MiddleCenter;
    RadGridView1.MasterTemplate.Columns.AddRange(new   Telerik.WinControls.UI.GridViewDataColumn[] {colText,colBtnDelete});

// add rows to grid
   GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(RadGridView1.MasterView);
   rowInfo.Cells[0].Value = "1";
   rowInfo.Cells[1].Value = "X"; // text for delete button
   RadGridView1.Rows.Add(rowInfo);

  rowInfo = new GridViewDataRowInfo(RadGridView1.MasterView);
  rowInfo.Cells[0].Value = "2";
  rowInfo.Cells[1].Value = "X";
  RadGridView1.Rows.Add(rowInfo);

  rowInfo = new GridViewDataRowInfo(RadGridView1.MasterView);
  rowInfo.Cells[0].Value = "3";
  rowInfo.Cells[1].Value = "X";
  RadGridView1.Rows.Add(rowInfo);
}

private void RadGridView1_CommandCellClick(object sender, EventArgs e)
{
   // handle CommandCellClick event
    GridCommandCellElement _cmd =(GridCommandCellElement)(sender);
    // if  text for delete button = X
    if ( _cmd.Value.ToString() == "X"
        RadGridView1.Rows.Remove(RadGridView1.CurrentRow); // remove current row
}
}
}






Duplicate rows in Oracle

Oracle > Scripts

SQL Query to find duplicate rows in Oracle

SELECT
  *
FROM
  table_name A
WHERE
  A.rowid >
  ANY (SELECT B.rowid FROM  table_name B WHERE
             A.col1 = B.col1
            AND
             A.col2 = B.col2
             )




Export to Excel Hierarchial data in the RadGridView

Telerik > RadGridView

ExportToExcelML method exports an image of an element to Excel file

ExportHierarchy property set if child rows should be exported


Example:

ExportToExcelML excelExporter = new ExportToExcelML(radGridView);
excelExporter.ExportHierarchy = true;
excelExporter.RunExport(filePath);





Concatenate string VB.NET

VB.NET > String > Concatenate

You can use +, & operators and Concat method.
Concat concatenates one or more instances of String.

The + and & operators are not identical in VB.NET.
  • & is only used for string concatenation
  • + is overloaded to do both string concatenation and arithmetic addition.

Example

1. Using & operator with strings

Dim str1 As String = "Visual "
Dim str2 As String = "Basic"
' Concatenate
Dim str3 = str1 & str2
MessageBox.Show(str3)


 
2. Using & operator with string and number

Dim str1 As String = "Visual Basic "
Dim str2 As Integer = 6

' Concatenate
Dim str3 = str1 & str2
MessageBox.Show(str3)


3. Concat Method

Dim str1 As String = "Visual"
Dim str2 As Integer = 6
' Concatenate
Dim str3 = String.Concat(str1, " ", str2)
MessageBox.Show(str3)





Thursday, January 10, 2013

First and Last day of a Month VB .NET

VB.NET > Functions > > DateSerial

Returns a Date value representing a specified year, month, and day, with the time information set to midnight (00:00:00).

Examples


First and last day of a month

VB.net
' first day of month
FirstDay = DateSerial(Today.Year, Today.Month, 1)
' month's last day
LastDay = DateSerial(Today.Year, Today.Month , 0)

C#

DateTime firstDayOfTheMonth = new DateTime(DateTime.Today.Year,DateTime.Today.Month, 1);
DateTime lastDayOfTheMonth = firstDayOfTheMonth.AddMonths(1).AddDays(-1);






Tuesday, January 8, 2013

Add Rows to RadGridView WinForms VB.NET

Telerik > RadGridView > Rows

GridViewRowInfo is the logical representation of a single row.

Examples

1. Add rows

You can add rows by creating an instance of GridViewDataRowInfo and adding it to the Rows collection of RadGridView

Dim rowInfo As New GridViewDataRowInfo(Me.RadGridView1.MasterView)
rowInfo.Cells(0).Value = "new row"
RadGridView1.Rows.Add(rowInfo)





Friday, January 4, 2013

Print RadGridView Telerik Windows Forms (VB.NET)

Telerik > Windows Forms > Print RadGridView

RadPrintDocument
Defines a reusable object that sends output to a printer and manages the whole printing process, when printing from an application

PrintPreviewDialog
Represents a dialog box form that contains a PrintPreviewControl for printing from a Windows Forms application.

AssociatedObject
 Gets or sets the object, associated with this document.

Print directly

Example:

Dim dialog As New PrintPreviewDialog
Dim RadPrintDocument1 As New RadPrintDocument
RadPrintDocument1.AssociatedObject = Me.RadGridView1
RadPrintDocument1.MiddleHeader = lblTitle.Text
RadPrintDocument1.MiddleFooter = "Page [Page #] of [Total Pages]"
RadPrintDocument1.RightFooter = "[Date Printed]"
dialog.Document = RadPrintDocument1
dialog.StartPosition = FormStartPosition.CenterScreen
dialog.ShowDialog()