Archive for the ‘Web’ Tag

How to use .NET dataGridView component to display twitter timeline using C#

Hey, this would be a basic tutorial about how to use the daytaGridView component to display your friends timeline.

Requirements:

-Visual Studio Express 2008

-Twitterizer Framework

1. Add the twitterizer library to the project

Menu>Project>Add Reference…

01tutorial

Select the current path of the Twitterizer libray that you donwloaded

02tutorial

2. Add the Twitterizer libray to the project

using Twitterizer.Framework;


3. Add the dataGridView component to the interface

Toolbox>data>dataGridView

13tutorial

4. Also add a button with the text “Update timeline”

14tutorial

5. Create a method called updateTimeline with no parameters like this:

private void updateTimeline()
{
Twitter t =new Twitter(“user”, “password”);
try
{
dataGridView1.DataSource = t.Status.FriendsTimeline(Parameters);
}
catch (TwitterizerException ex)
{
MessageBox.Show(this, ex.Message, “Error”);
}
}

private void updateTimeline()

{

Twitter t =new Twitter(“user”, “password”);
try
{
dataGridView1.DataSource = t.Status.FriendsTimeline(Parameters);
}
catch (TwitterizerException ex)
{
MessageBox.Show(this, ex.Message, “Error”);
}
}

6. Double click through the button and call the method that we had created before.

private void buttonSignIn_Click(object sender, EventArgs e)

{

updateTimeline();

}

7. Run your application to see your Friends Timeline status.

03tutorial

As you can see, theres too much information in the dataGridView, so we need to chage some properties in order to improve the appearence of the timeline.
8. In the design view, look for a play button in the dataGridView component and click on it
04tutorial
Then clic on Edit Columns

First colum is for the user06tutorial

the second one is for the status
07tutorial
9. Then bind the colums with some property like this
The column Status will show the data from the Text column

08Tutorial
The column User will show the data from the TwitterUser column
09Tutorial
10. Add this line of code to the method UpdateTimeline

private void updateTimeline()

{
Twitter t = new Twitter(“user”, “password”); //use your own username and password
try
{
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = t.Status.FriendsTimeline();
}
catch (TwitterizerException ex)
{
MessageBox.Show(this, ex.Message, “Error”);
}
}
//with this the dataGridView won’t add more columns
11. Run your application and watch the new interface
11tutorial

12. Finally your code should be like this
12tutorial

Ok this is a basic tutorial of how to use the dataGridView component to display the twitter timeline, but of course, the dataGridView compont has a lot of methods and properties to change the behavior of this component.
I hope this tutorial will be helpfull for this persons who are starting with twitter application using the twitterizer framework.
WebLab|Osvaldo Huerta

Advertisements