Tuesday, July 3, 2012

Save VsFlexGrid data to excel


  1. Private Sub FlexToExcel()
  2. Dim xlObject    As Excel.Application
  3. Dim xlWB        As Excel.Workbook
  4.        
  5.     Set xlObject = New Excel.Application
  6.     'This Adds a new woorkbook, you could open the workbook from file also
  7.     Set xlWB = xlObject.Workbooks.Add
  8.                
  9.     Clipboard.Clear 'Clear the Clipboard
  10.     With MSFlexGrid1
  11.         'Select Full Contents (You could also select partial content)
  12.         .Col = 0               'From first column
  13.         .Row = 0               'From first Row (header)
  14.         .ColSel = .Cols - 1    'Select all columns
  15.         .RowSel = .Rows - 1    'Select all rows
  16.         Clipboard.SetText .Clip 'Send to Clipboard
  17.     End With
  18.            
  19.     With xlObject.ActiveWorkbook.ActiveSheet
  20.         .Range("A1").Select 'Select Cell A1 (will paste from here, to different cells)
  21.         .Paste              'Paste clipboard contents
  22.     End With
  23.    
  24.     ' This makes Excel visible
  25.     xlObject.Visible = True
  26. End Sub

Monday, July 2, 2012

Binding Combobox at run time without using database connection via Dictionery Objec

        Dim objDict As New Dictionary(Of String, String)
        objDict.Add("1", "Value 1")
        objDict.Add("2", "Value 2")


        ComboBox1.DataSource = New BindingSource(objDict, Nothing)
        ComboBox1.DisplayMember = "Value"
        ComboBox1.ValueMember = "Key"

Saturday, June 30, 2012

Difference between Panel and GroupBox classes in .NET

The both classes that is Panel and GroupBox can be used as a container for other controls such as check box control, radio button control etc. But the difference between these two classes is 
• In case of Panel class captions cannot be displayed i.e. we can’t set caption but in GroupBox class captions can be displayed. 
• The Panel class can have scroll bars but GroupBox class cannot have scroll bar.

Thursday, June 28, 2012

Add row to bound Datagrideview


        Dim dr As DataRow = CType(DgviewDetail.DataSource, DataTable).NewRow
        dr.Item(1) = "anand"

        'DgviewDetail.Rows.Add(dr)

        CType(DgviewDetail.DataSource, DataTable).Rows.Add(dr)

Wednesday, June 13, 2012

excel connection string



ExcelCon = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + WorkBook + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1;';")

Monday, May 7, 2012

to set database owner

use databasename

sp_changedbowner

user_name