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).  

image

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)
    da.Fill(dt)
    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 DotNetKicks.com
Tags:
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 http://lowest-rate-loans.com/topics/credit-loans">credit loans to solve all the problems. Hence take a term loan to buy everything you want.

NegeriAds.com Solusi BerpromosiNegeriAds.com Solusi Berpromosi said:

Tnks Advance

www.masjoe.com/...-solusi-berpromosi-yang-oke.html" title="NegeriAds.com Solusi Berpromosi">NegeriAds.com Solusi Berpromosi
www.masjoe.com/catatan-blogger-seo-matre-ajib.html" title="Catatan Blogger Seo Matre Ajib">Catatan Blogger Seo Matre Ajib
www.masjoe.com/...monumen-nasional-atau-monas.html" title="Tugu Monumen Nasional atau Monas">Tugu Monumen Nasional atau Monas
http://www.masjoe.com/museum-gajah.html" title="Museum Gajah">Museum Gajah
http://www.masjoe.com/tukaran-link.html" title="Tukaran Link">Tukaran Link
http://www.masjoe.com/disclaimer.html" title="Disclaimer">Disclaimer
www.masjoe.com/31-tips-menaikan-trafik-blog.html" title="31 Tips Menaikan Trafik Blog">31 Tips Menaikan Trafik Blog
www.masjoe.com/...-book-for-wordpress-gratiss.html" title="Download SEO Book for WordPress Gratiss">Download SEO Book for WordPress Gratiss
www.masjoe.com/...ri-kontes-seo-negeriads-com.html" title="Uang 14 Juta rupiah dari Kontes SEO NegeriAds.com">Uang 14 Juta rupiah dari Kontes SEO NegeriAds.com
http://www.masjoe.com/selamat-datang.html" title="Selamat Datang">Selamat Datang
www.masjoe.com/memahami-seo-melalui-comic.html" title="Memahami Seo melalui Comic">Memahami Seo melalui Comic
www.masjoe.com/...ging-terhadap-motivasi-diri.html" title="Efek Blogging terhadap Motivasi diri">Efek Blogging terhadap Motivasi diri
www.masjoe.com/...ebuah-film-any-given-sunday.html" title="Inspirasi dari Sebuah Film Any Given Sunday">Inspirasi dari Sebuah Film Any Given Sunday
www.masjoe.com/cara-membuat-avatar-online.html" title="cara Membuat Avatar Online">cara Membuat Avatar Online
inuel.info/catatan-blogger-seo-matre-ajib.html" 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. http://www.nikeairmax4u.com">Nike air max as one of the most classic series, the use of innovative technology to enable movement and style in this clever blend. www.nikeairmax4u.com/nike-air-max-1-c-1.html">Nike air max 1 from http://www.nikeairmax4u.com" title="http://www.nikeairmax4u.com">http://www.nikeairmax4u.com

Comments are closed