Search This Blog

Tuesday, January 15, 2013

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)