tags:

views:

49

answers:

4

Hi!

I'm creating a twitter client in C#. I want to put every tweet as an element of a listbox. I created a windows form that represents a tweet(it has a picture, and labels).

My problem is that when i can't see the tweets when i add them to the listbox. After adding 3 tweets(windows form objects), the listbox has 3 blank elements in them, but i can't see anything of it.

How can i add a windows form object to a listbox?

(these forms are working fine, because i can see them if i use the ShowDialog method)

please help

A: 

I don't think ListBox can display anything but a text string for each element, so you won't be able to see an image of each form if that's what you were hoping for. You might try using FlowLayoutPanel instead to manage a list of controls.

+1  A: 

You can add a Form object to the ListBox.Items collection but the only thing you'll ever see is the type name of the form. ListBox is not capable of rendering controls as its items.

The efficient solution is to implement the ListBox.DrawItem event and custom draw the tweet. There's a good example of such an event handler in the MSDN Library documentation for the event.

The slow solution is to add controls to a Panel's Collection property with its AutoScroll property set to true. That cannot be a form, it must be a UserControl.

Hans Passant
This sounds the way i would like to do it, however, i can't really find out exactly how. my GUI looks like this:
public GUI(TwitterControl TwitterControl) { InitializeComponent(); List<OneTweet> _list = new List<OneTweet>(); OneTweet first = new OneTweet("Zoli", "This is my first tweet", DateTime.Now); OneTweet second = new OneTweet("Niiki", "This is my second tweet", DateTime.Now); OneTweet third = new OneTweet("Eme", "This is my third tweet", DateTime.Now); _list.Add(first); _list.Add(second); _list.Add(third); _tweetList.DataSource = _list; }
and oneTweet looks like this:public partial class OneTweet : Form { public OneTweet(string author, string message, DateTime postDate) { InitializeComponent(); _authorName.Text = author; _message.Text = message; _postDate.Text = postDate.ToString(); } }
how shoul i modify it to make it work?
Oh Lord, put it in your question, not a comment.
Hans Passant
+1  A: 

You may want to look into implementing it using WPF. Where you can pretty much put anything inside a listbox.

Vivek
+1  A: 

Some thoughts:

  1. You'd do better to work with custom controls, rather than a whole form
  2. A listbox can't have controls on it... consider a ListView: http://www.codeproject.com/KB/list/ListViewEmbeddedControls.aspx
  3. Some example code of what you're trying will help us zoom in on what you're doing

HTH, James

James B