vbdotnet.it

Tricks & tips, workaround, forum and ideas with .Net

About the author

Enrico Rossini è il gestore di questo blog.
E-mail me Send mail

Recent posts

Recent comments

Contributi

Best 6 ~ 6 users ~ 6 comments

Info legali

Le opinioni espresse in questo blog sono strettamente personali e ogni persona è responsabile dei commenti che inserisce. I marchi citati sono delle rispettive aziende.

© Copyright 2010

Advertising


Un metodo velocissimo per leggere un RSS

Questo è il più semplice modo per leggere un RSS... 

Dim ds as DataSet = new DataSet()
ds.ReadXml("http://www.vbdotnet.it/syndication.axd",XmlReadMode.Auto)

DataGrid1.DataSource=ds.Tables(2)
DataGrid1.DataBind()

Ciao a tutti!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Thursday, April 30, 2009 1:46 PM
Permalink | Comments (0) | Post RSSRSS comment feed

L'usercontrol è in ambiente di designtime?

Se si è alle prese con la realizzazione di un Usercontrol potrebbe essere utile determinare se il componente stesso si trova in design-time (come ad esempio all’interno di un form in Visual Studio) o se è in runtime.

Per poter verificare questo basta utilizzare il seguente codice:

   1: ' verifica se il componente è in esecuzione a runtime
   2: If System.ComponentModel.LicenseManager.UsageMode = LicenseUsageMode.Runtime Then
   3:    ' esegue altro codice
   4: End If

Ciao.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Thursday, April 16, 2009 7:30 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Togliere lo scrollbar da un textbox quando non server

Non so se anche a voi è capitato ma mi sembra utile postarlo. Se hai un TextBox con una scrollbar e vuoi nascondere la scrollbar quando questa è inutile, come si può fare?

Ecco il codice (txtTesto è il nostro TextBox):

   1: Private Sub txtTesto_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTesto.TextChanged
   2:     Static busy As Boolean
   3:     If busy Then Exit Sub
   4:     busy = True
   5:  
   6:     With sender
   7:         Dim tS = TextRenderer.MeasureText(.Text, .Font)
   8:         Dim Hsb = .ClientSize.Height < tS.Height + .Font.Size
   9:         Dim Vsb = .ClientSize.Width < tS.Width
  10:  
  11:         If Hsb And Vsb Then
  12:             .ScrollBars = ScrollBars.Both
  13:         ElseIf Not Hsb And Not Vsb Then
  14:             .ScrollBars = ScrollBars.None
  15:         ElseIf Hsb And Not Vsb Then
  16:             .ScrollBars = ScrollBars.Vertical
  17:         Else
  18:             .ScrollBars = ScrollBars.Horizontal
  19:         End If
  20:     End With
  21:     busy = False
  22: End Sub

Ciao!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Friday, April 10, 2009 1:42 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Leggere un file Microsoft Excel 97/2003 o 2007

La funzione che presento oggi consente di importare un foglio di Microsoft Excel in un dataset nelle versioni 97, 2003 e 2007.

 

   1: ''' <summary>
   2: ''' Reads the data from excel.
   3: ''' </summary>
   4: ''' <param name="excelfilename">The excelfilename.</param>
   5: ''' <returns></returns>
   6: Function ReadDataFromExcel(ByVal excelfilename As String) As DataSet
   7:     Dim ds As New DataSet
   8:     Dim da As OleDbDataAdapter
   9:     Dim conn As OleDbConnection
  10:  
  11:     Try
  12:         If System.IO.Path.GetExtension(excelfilename) = ".xls" Then
  13:             conn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & excelfilename & "; Extended Properties=Excel 8.0;")
  14:         ElseIf System.IO.Path.GetExtension(excelfilename) = ".xlsx" Then
  15:             conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & excelfilename & "; Extended Properties=Excel 8.0;")
  16:         End If
  17:  
  18:         da = New OleDbDataAdapter("SELECT * FROM [Foglio1$]", conn)
  19:  
  20:         conn.Open()
  21:         da.Fill(ds)
  22:     Catch ex As Exception
  23:         MsgBox(ex.Message)
  24:     Finally
  25:         If conn.State = ConnectionState.Open Then
  26:             conn.Close()
  27:         End If
  28:     End Try
  29:     ReadDataFromExcel = ds
  30: End Function

Buon lavoro e ricordatevi il nostro forum!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by enrico on Tuesday, April 07, 2009 7:32 PM
Permalink | Comments (0) | Post RSSRSS comment feed