Click here to Skip to main content
Click here to Skip to main content

Data Repeater Control in Windows Applications

, 29 Oct 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
An alternative way to use data repeater control in windows application.


I worked with data repeater control in web application and i wanted to use one in windows application i was assigned to. I must admit, i had a hard time getting it to work. The only help on internet was - to use a database connection as data source and then to drag-drop relative fields on repeater control's surface. I did not find it suitable for my needs. I just can't show a data table contents to a user.


A data repeater control takes advantage of a 'collection'. We need to declare the fields we want to show, and then we need to have a collection consisting those fields with our data(formatted/after applying business logic). On internet, data repeater control was bind to a data table. A data table essentially is a collection.

Using the code

As a starting point, I created a class in my application. A very simple class with two class variables and relative public properties. Then i created a constructor in that class so that I can initialize an object with data. Below is the code of that entire class.

using System;
using System.Collections.Generic;
using System.Text;

namespace testWinFormsRepeater.DataSourceForDataRepeaterControl
    public class clsDataRepeaterTemplateData
        private string m_msg = string.Empty;
        private string m_sub = string.Empty;

        public string Message
                return this.m_msg;

        public string Subject
                return this.m_sub;

        public clsDataRepeaterTemplateData(string msg, string sub)
            this.m_msg = msg;
            this.m_sub = sub;
  • Change the namespace of your class to make it distinctive. It will help later. I added ".DataSourceForDataRepeaterControl" to the original namespace as you may notice above.
  • I needed to rebuild my project in order to have this namespace get reflected.

Then I added a windows form to my project. And a data repeater control on it.


The next step was to add a data source to this repeater control. I opened 'Data Sources' window to add one.

  • If 'Data Sources' window is not open in your visual studio, you may find it using "Data->Show Data Sources" or by pressing "Shift+Alt+D".


Clicking 'Add New Data Source' will open a wizard for adding a data source to your project.


Select 'Object' and click 'Next'.


As can be seen above, we will be presented with options to select our class (data source schema, here). Select your class under the modified namespace. Click Finish.

  • If you did not opt for having a distinctive namespace while creating a class, you may need to find your class under the default namespace.
  • Having a distinctive namespace is helpful in a scenario when you are using more than one class as data sources. With the approach of having an exclusive namespace for themselves, all 'classes as data sources' will club themselves together under one namespace here.

As soon as we click 'Finish', we are back in our 'Data Sources' window with one data source listed.

  • This data source is reflection of your class. If you declare a public class variable, it would be shown here too.
  • Note that the fields shown in your data source now, are actually the public properties of your class. Being a property, it provides us an option to modify the output ( we can code our desired functionality in 'get' section of desired property). Data repeater control will show a value determined by 'get' section of property.


Now you can drag-drop the data fields you wish to appear on data repeater control. In our test application as seen above, if you drag both data fields your windows form should look like the image below:


Our data repeater control is set. Now only data is required.

In Form_Load event of your form, assign the data source of your data repeater control a list. The list should contain objects of your special class. The code below should explain this condition itself:

private void Form1_Load(object sender, EventArgs e)
    this.dataRepeater1.DataSource = getDataForDataRepeaterControl();

private List<testWinFormsRepeater.DataSourceForDataRepeaterControl.clsDataRepeaterTemplateData> getDataForDataRepeaterControl()
    List<testWinFormsRepeater.DataSourceForDataRepeaterControl.clsDataRepeaterTemplateData> lst = new List<DataSourceForDataRepeaterControl.clsDataRepeaterTemplateData>();
    for (int i = 0; i <= 9; i++)
        lst.Add(new DataSourceForDataRepeaterControl.clsDataRepeaterTemplateData("msg no. " + i.ToString(), "sub no. " + i.ToString()));
    return lst;

Here, we are creating a collection of our class' objects. In the example above, List<> collection is used. After creating this collection, we are assigning it to the DataSource property of our data repeater control.

Rebuild and Run your project. In Form1, you should be able to see data repeater control with data.

Points of Interest

This article is to give you a start with Repeater control in Windows application. I could not find anything which could tell me alternative ways to bind and use a data repeater control in windows application. So I thought it may be helpful for someone else who does not want to use data repeater with a data table only.

There may be events of data repeater control which can enforce the functionality we achieved above. I don't know them. I got what I wanted in my application through above procedure and thought of sharing it. If someone knows other ways also, please share them.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

No Biography provided

Comments and Discussions

GeneralMessage Automatically Removed Pinmember.:floyd:.25-Aug-14 3:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150327.1 | Last Updated 29 Oct 2012
Article Copyright 2012 by gaurav_mittal
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid