• Viernes 29 de Marzo de 2024, 03:37

Autor Tema:  listbox y colecciones  (Leído 2719 veces)

Jimi_26

  • Nuevo Miembro
  • *
  • Mensajes: 11
    • Ver Perfil
listbox y colecciones
« en: Sábado 16 de Agosto de 2014, 12:49 »
0
Hola!
estoy pasando un listado a un lisbox a traves de un arraylist. El hecho es que cuando coloco las frases o palabras en ¡el listbox1, me aparece previo a éstas, la definición " (Colección) " , con lo que, si le paso 3 frases antes me aparece en el listbox algo asi:

(colección)
(colección)
(colección)
frase1
frase 2
frase3

He tratado de ver si es un detalle de las propiedades del listbox, pero no he encontrado nada...solo una propiedad donde indica de donde se sacan los datos, que por defecto esta en "collection" ( y si no se puede modificar por tablas...).
¿ Cómo puedo quitar esas notificaciones de (coleccion) en mi listado?

Grácias

gabio2

  • Miembro MUY activo
  • ***
  • Mensajes: 402
  • Nacionalidad: mx
    • Ver Perfil
Re:listbox y colecciones
« Respuesta #1 en: Lunes 18 de Agosto de 2014, 03:06 »
0
Podrías colocar el código donde llenas el listbox, para ver en donde está el posible error.

Saludos!
@gabio87

Jimi_26

  • Nuevo Miembro
  • *
  • Mensajes: 11
    • Ver Perfil
Re:listbox y colecciones
« Respuesta #2 en: Miércoles 20 de Agosto de 2014, 18:45 »
0
Hola gabio, la verdad es que he decidido hacerlo todo desde dos listbox diferentes, muucho mas fácil para programar. Mi idea era crear una clase con 2 strings mas un reproductor de sonido de uno de esos dos string:

la clase:
Código: C#
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Collections;
  7. using System.IO;
  8. using System.Media;
  9. namespace WindowsFormsApplication1
  10. {
  11.     class FrasesSonido
  12.     {
  13.         public string FraseEspañol { get; set; }
  14.         public string FraseRuso { get; set; }
  15.         public string rutaArchivoSonido { get; set; }
  16.         public SoundPlayer sonido = new SoundPlayer();
  17.        
  18.        
  19.  
  20.         public string Reporte()      
  21.         {
  22.            
  23.             string Mensaje = string.Format("  {0}", FraseEspañol);
  24.             return Mensaje;
  25.         }
  26.  
  27.         public string Reporte2()
  28.         {
  29.             string Mensaje2 = string.Format("{0}", FraseRuso);
  30.             return Mensaje2;
  31.         }
  32.     }
  33. }
  34.  

y el form:
Código: C#
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Collections;
  11. using System.Media;
  12.  
  13.  
  14.  
  15.  
  16.  
  17. namespace WindowsFormsApplication1
  18.    
  19. {
  20.     public partial class Form1 : Form
  21.     {
  22.         public Form1()
  23.         {
  24.             InitializeComponent();
  25.            
  26.         }
  27.         ArrayList  listado = new ArrayList();
  28.        
  29.         private void  button1_Click(object sender, EventArgs e)
  30.         {
  31.  
  32.          
  33.             ///// frase 1 /////////
  34.             FrasesSonido f1 = new FrasesSonido();
  35.             f1.FraseEspañol = "Hola";
  36.             f1.FraseRuso = "Привет";
  37.             f1.rutaArchivoSonido= f1.sonido.SoundLocation = "C:/Users/jimi/Documents/Visual Studio 2012/Projects/Idiomas/prueba.wav";          
  38.             //f1.sonido.Play();
  39.            
  40.             ///// frase 2 /////////
  41.             FrasesSonido f2 = new FrasesSonido();
  42.             f2.FraseEspañol = "Adiós";
  43.             f2.FraseRuso = "Пока";
  44.             f2.rutaArchivoSonido = f2.sonido.SoundLocation = "C:/Users/jimi/Documents/Visual Studio 2012/Projects/Idiomas/prueba.wav";
  45.             //f2.sonido.Play();
  46.  
  47.             ///// frase 3 /////////
  48.             FrasesSonido f3 = new FrasesSonido();
  49.             f3.FraseEspañol = "¿Cómo está usted?";
  50.             f3.FraseRuso = "как дела?";
  51.             f3.rutaArchivoSonido = f2.sonido.SoundLocation = "C:/Users/jimi/Documents/Visual Studio 2012/Projects/Idiomas/prueba.wav";
  52.             //f3.sonido.Play();
  53.  
  54.             ///// frase 4 /////////
  55.             FrasesSonido f4 = new FrasesSonido();
  56.             f4.FraseEspañol = "Bien";
  57.             f4.FraseRuso = "harasho";
  58.             f4.rutaArchivoSonido = f4.sonido.SoundLocation = "C:/Users/jimi/Documents/Visual Studio 2012/Projects/Idiomas/prueba.wav";
  59.             //f4.sonido.Play();
  60.  
  61.             ///// frase 5 /////////
  62.             FrasesSonido f5 = new FrasesSonido();
  63.             f5.FraseEspañol = "aaaaa1";
  64.             f5.FraseRuso = "aaaaa2";
  65.             f5.rutaArchivoSonido = f4.sonido.SoundLocation = "C:/Users/Jimi/Documents/Visual Studio 2012/Projects/Idiomas/prueba.wav";
  66.             //f5.sonido.Play();
  67.  
  68.  
  69.  
  70.             //// agregar a listado //////
  71.            
  72.  
  73.  
  74.             listado.Add(f1);
  75.             listBox1.Items.Add(f1.FraseEspañol);
  76.            // listBox1.Items.Add(listado);
  77.          
  78.          
  79.            
  80.  
  81.             listado.Add(f2);
  82.             listBox1.Items.Add(f2.FraseEspañol);
  83.             //listBox1.Items.Add(listado);
  84.  
  85.             listado.Add(f3);
  86.             listBox1.Items.Add(f3.FraseEspañol);
  87.             //.Items.Add(listado);
  88.  
  89.             listado.Add(f4);
  90.             listBox1.Items.Add(f4.FraseEspañol);
  91.             //listBox1.Items.Add(listado);
  92.  
  93.             listado.Add(f5);
  94.             listBox1.Items.Add(f5.FraseEspañol);
  95.             //listBox1.Items.Add(listado);
  96.  
  97.  
  98.            
  99.             //MostrarEnListBoxYTextBox();
  100.             textBox2.Text = listado.Count.ToString();// longitud total actual del listBox
  101.            
  102.             //// mostrar todo lo añadido en ListBox1
  103.            
  104.            
  105.         }
  106.  
  107.         public void MostrarEnListBox()
  108.         {
  109.            
  110.         }
  111.  
  112.  
  113.         public void MostrarEnListBoxYTextBox()
  114.         {
  115.  
  116.             foreach (object objeto in listado)
  117.             {
  118.                 FrasesSonido frasex = (FrasesSonido)objeto;
  119.                 listBox1.Items.Add(frasex.Reporte().ToString());
  120.                 textBox1.Text = frasex.Reporte2().ToString();
  121.                
  122.  
  123.             }
  124.         }
  125.  
  126.         public  void listView1_SelectedIndexChanged(object sender, EventArgs e)
  127.         {
  128.             // Get the currently selected item in the ListBox.
  129.             string curItem = listBox1.SelectedItem.ToString();
  130.             textBox1.Text = curItem;
  131.             PosicionSeleccionEnListBox(sender, e);
  132.  
  133.  
  134.            
  135.             txtbPosicionActualListado.Text= listado.Count.ToString();
  136.            // PosicionSeleccionEnArrayList();
  137.             txtbPosicionActualListado.Text = listado.Count.ToString();
  138.             MessageBox.Show("el tamaño de list box es " + listBox1.Items.Count.ToString());
  139.             MessageBox.Show("el tamaño de ArrayList  " +  listado.Count);
  140.  
  141.         }
  142.  
  143.  
  144.         public void  PosicionSeleccionEnListBox(object sender, EventArgs e)
  145.         {
  146.             int item =listBox1.SelectedIndex;
  147.             textBox3.Text = item.ToString() ;
  148.         }
  149.  
  150.         public void PosicionSeleccionEnArrayList()
  151.         {
  152.             int item = listBox1.SelectedIndex,i=0;
  153.             for ( i = 0; i <= listado.Count;i++ )  // recorrer listbox1 y array list en busqueda de igualdades
  154.             {
  155.                 if (listBox1.Text == listado[i].ToString())
  156.                 {
  157.                     MessageBox.Show("coinidencia en :" + listado[i].ToString());
  158.                 }
  159.                 string ic= item.ToString();
  160.                
  161.                
  162.             }
  163.         }
  164.  
  165.         private void listView1_SelectedIndexChanged_1(object sender, EventArgs e)
  166.         {
  167.  
  168.         }
  169.  
  170.     }//
  171. }
  172.  


Bueno parte de codigo me sirve para ver en que posicion guarda cada string y demas, (me fastidia un poco ver las variables por debugger)