Ken Tucker Blog

Adventures in .net

VB Power Packs DataRepeater control

Thursday, February 21, 2008

In Feburary 2008 the VB Power packs team released version 3 of there VB Power Packs 2005.  This version included a DataRepeater control.

               The DataRepeater control allows you use standard windows controls to display your data in a scrollable container.   The included documentation shows you how to bind the DataRepeater to a typed dataset.  This article will show you how to bind to a datatable in code. 

               To start off with create a new windows forms application and drop a datarepeater on the form.  In the datarepeater drop a picturebox (pbCategory) and a label (lblName).  


In the forms load event lets add some code to connect to the database.  I am binding the datarepeater to a bindingsource because it is a good practice. 

Dim bs As New BindingSource

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim conn As New SqlConnection("Server = .\SQLExpress;Database = NorthWind; Integrated Security = SSPI;")
    Dim dt As New DataTable

    Dim da As New SqlDataAdapter("Select * from Categories", conn)
    bs.DataSource = dt

    DataRepeater1.DataSource = bs
End Sub

The DataRepeater has a DrawItem event which allows us to put the data in the controls for each item.  You can also use this event for formatting the data for display

Private Function GetBitmap(ByVal Pic() As Byte) As Bitmap
    Dim ms As New System.IO.MemoryStream
    Dim bm As Bitmap
    ms.Write(Pic, 78, Pic.Length - 78)
    bm = New Bitmap(ms)
    Return bm
End Function

Private Sub DataRepeater1_DrawItem(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.PowerPacks.DataRepeaterItemEventArgs) Handles DataRepeater1.DrawItem
    Dim currItem As DataRowView = bs.Item(e.DataRepeaterItem.ItemIndex)

    DirectCast(e.DataRepeaterItem.Controls("pbCategory"), PictureBox).Image = GetBitmap(DirectCast(currItem.Item("Picture"), Byte()))
    DirectCast(e.DataRepeaterItem.Controls("lblName"), Label).Text = currItem.Item("CategoryName").ToString
End Sub

kick it on
Filed Under: VB

Comments (4) -

LynchClaraLynchClara said:

Don't have cash to buy a building? Don't worry, because it is achievable to get the">credit loans to solve all the problems. Hence take a term loan to buy everything you want. Solusi Solusi Berpromosi said:

Tnks Advance" title=" Solusi Berpromosi"> Solusi Berpromosi" title="Catatan Blogger Seo Matre Ajib">Catatan Blogger Seo Matre Ajib" title="Tugu Monumen Nasional atau Monas">Tugu Monumen Nasional atau Monas" title="Museum Gajah">Museum Gajah" title="Tukaran Link">Tukaran Link" title="Disclaimer">Disclaimer" title="31 Tips Menaikan Trafik Blog">31 Tips Menaikan Trafik Blog" title="Download SEO Book for WordPress Gratiss">Download SEO Book for WordPress Gratiss" title="Uang 14 Juta rupiah dari Kontes SEO">Uang 14 Juta rupiah dari Kontes SEO" title="Selamat Datang">Selamat Datang" title="Memahami Seo melalui Comic">Memahami Seo melalui Comic" title="Efek Blogging terhadap Motivasi diri">Efek Blogging terhadap Motivasi diri" title="Inspirasi dari Sebuah Film Any Given Sunday">Inspirasi dari Sebuah Film Any Given Sunday" title="cara Membuat Avatar Online">cara Membuat Avatar Online" title="Catatan Blogger Seo Matre Ajib">Catatan Blogger Seo Matre Ajib

nike air shoesnike air shoes said:

BCFGDCGDG NIKE English intent of the Greek goddess of victory.">Nike air max as one of the most classic series, the use of innovative technology to enable movement and style in this clever blend.">Nike air max 1 from" title="">

Comments are closed