[Mono-winforms-list] Re: [Mono-devel-list] I can't have the listbox working

Arnoux Vincent varnoux@atmel.fr
Mon, 24 Nov 2003 11:34:08 +0100


This is a multi-part message in MIME format.
--------------090204010508000909040206
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

OK, I didn't have a lot of success with this question, however I will 
give it a second try because I really can't figure out the reason why it 
is not working.
Actually, the problem comes from the variable listBox.SelectedItem that 
looks to be null.
I also did a test with listbox.SelectedItems[0]...
Does anybody has any idea ?

Vincent

Arnoux Vincent wrote:

> Dear list members,
> I tried a few things but couldn't make the following code displaying 
> my selected listbox item (i.e. the string "Selected item:" is 
> displayed, but nothing, even a blank line for the item itself).
> This works on .net, but doesn't want to on mono.
> Did I miss anything obvious ?
>
> /#define DEBUG
> // created on 11/11/2003 at 12:08
> using System;
> using System.Collections;
> using System.Windows.Forms;
>
>
> public class CreatedForm : System.Windows.Forms.Form
> {
>    private System.Windows.Forms.ListBox listBox;
>    public CreatedForm()
>    {
>        InitializeComponent();
>        start();
>    }
>      void InitializeComponent() {
>        this.listBox = new System.Windows.Forms.ListBox();
>        this.SuspendLayout();
>        //
>        // listBox
>        //
>        //this.listBox.Location = new System.Drawing.Point(16, 16);
>        this.listBox.Name = "listBox";
>        //this.listBox.Size = new System.Drawing.Size(576, 199);
>        this.listBox.TabIndex = 0;
>        this.listBox.SelectedIndexChanged += new 
> System.EventHandler(this.ListBoxSelectedIndexChanged);
>        //
>        // CreatedForm
>        //
>        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
>        //this.ClientSize = new System.Drawing.Size(632, 446);
>        this.Controls.Add(this.listBox);
>        this.Name = "CreatedForm";
>        this.ResumeLayout(false);
>    }
>      public void start()
>    {
>        listBox.BeginUpdate();
>        for (int i = 0; i < 10; i++)
>        {
>            listBox.Items.Add("Item " + i);
>        }
>        listBox.EndUpdate();
>    }
>      public static void Main()
>    {
>        CreatedForm f = new CreatedForm();
>        Application.Run(f);
>    }
>      void ListBoxSelectedIndexChanged(object sender, System.EventArgs e)
>    {
>        Console.WriteLine("Selected item:");
>        Console.WriteLine(listBox.SelectedItem.ToString());
>    }
> }
>
> /Best regards,
> Vincent/
> /
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
>

--------------090204010508000909040206
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<font size="-1"><font face="Helvetica, Arial, sans-serif">OK, I didn't
have a lot of success with this question, however I will give it a
second try because I really can't figure out the reason why it is not
working.<br>
</font></font><font size="-1"><font face="Helvetica, Arial, sans-serif">Actually,
the problem comes from the variable </font></font>listBox.SelectedItem
<small><font face="Helvetica, Arial, sans-serif">that looks to be null.<br>
I also did a test with listbox.SelectedItems[0]...<br>
Does anybody has any idea ?<br>
<br>
Vincent<br>
<br>
</font></small>Arnoux Vincent wrote:<br>
<blockquote type="cite" cite="mid3FB9F296.3050106@atmel.fr">Dear list
members,
  <br>
I tried a few things but couldn't make the following code displaying my
selected listbox item (i.e. the string "Selected item:" is displayed,
but nothing, even a blank line for the item itself).
  <br>
This works on .net, but doesn't want to on mono.
  <br>
Did I miss anything obvious ?
  <br>
  <br>
/#define DEBUG
  <br>
// created on 11/11/2003 at 12:08
  <br>
using System;
  <br>
using System.Collections;
  <br>
using System.Windows.Forms;
  <br>
  <br>
  <br>
public class CreatedForm : System.Windows.Forms.Form
  <br>
{
  <br>
&nbsp;&nbsp; private System.Windows.Forms.ListBox listBox;
  <br>
&nbsp;&nbsp; public CreatedForm()
  <br>
&nbsp;&nbsp; {
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InitializeComponent();
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start();
  <br>
&nbsp;&nbsp; }
  <br>
&nbsp; &nbsp;&nbsp; void InitializeComponent() {
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.listBox = new System.Windows.Forms.ListBox();
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.SuspendLayout();
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // listBox
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //this.listBox.Location = new System.Drawing.Point(16, 16);
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.listBox.Name = "listBox";
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //this.listBox.Size = new System.Drawing.Size(576, 199);
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.listBox.TabIndex = 0;
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.listBox.SelectedIndexChanged += new
System.EventHandler(this.ListBoxSelectedIndexChanged);
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // CreatedForm
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //this.ClientSize = new System.Drawing.Size(632, 446);
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Controls.Add(this.listBox);
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Name = "CreatedForm";
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.ResumeLayout(false);
  <br>
&nbsp;&nbsp; }
  <br>
&nbsp; &nbsp;&nbsp; public void start()
  <br>
&nbsp;&nbsp; {
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listBox.BeginUpdate();
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; 10; i++)
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listBox.Items.Add("Item " + i);
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; listBox.EndUpdate();
  <br>
&nbsp;&nbsp; }
  <br>
&nbsp; &nbsp;&nbsp; public static void Main()
  <br>
&nbsp;&nbsp; {
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; CreatedForm f = new CreatedForm();
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Application.Run(f);
  <br>
&nbsp;&nbsp; }
  <br>
&nbsp; &nbsp;&nbsp; void ListBoxSelectedIndexChanged(object sender, System.EventArgs
e)
  <br>
&nbsp;&nbsp; {
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine("Selected item:");
  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Console.WriteLine(listBox.SelectedItem.ToString());
  <br>
&nbsp;&nbsp; }
  <br>
}
  <br>
  <br>
/Best regards,
  <br>
Vincent/
  <br>
/
  <br>
  <br>
  <br>
_______________________________________________
  <br>
Mono-devel-list mailing list
  <br>
<a class="moz-txt-link-abbreviated" href="mailto:Mono-devel-list@lists.ximian.com">Mono-devel-list@lists.ximian.com</a>
  <br>
<a class="moz-txt-link-freetext" href="http://lists.ximian.com/mailman/listinfo/mono-devel-list">http://lists.ximian.com/mailman/listinfo/mono-devel-list</a>
  <br>
  <br>
  <br>
  <br>
</blockquote>
</body>
</html>

--------------090204010508000909040206--