Un metodo velocissimo per leggere un RSS

by 30. aprile 2009 12.46

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!

Tags: ,

L'usercontrol è in ambiente di designtime?

by 16. aprile 2009 18.30

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.

Tags: , , ,

Togliere lo scrollbar da un textbox quando non server

by 10. aprile 2009 12.42

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!

Tags: , ,

Leggere un file Microsoft Excel 97/2003 o 2007

by 7. aprile 2009 18.32

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!

Tags: , , , ,

Page List

Calendar

<<  febbraio 2012  >>
lumamegivesado
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar