No se si lo he entendido bien...
Instancias una lista de la Class
Disco, y lo que quieres hacer es llenar un ComboBox que contenga los distintos "Generos" da los items de la lista de
Disco?
Entonces solo tienes que seleccionar la propiedad "
genero" de cada item
Disco, lo puedes hacer con una query de
LINQ o con un
For:
VB.NetImports System.Globalization
Imports System.Threading
Public Class Form1
Public Shared listaDisco As New List(Of Disco) From
{
New Disco With {.titulo = "a", .genero = "Rock"},
New Disco With {.titulo = "b", .genero = "Pop"},
New Disco With {.titulo = "c", .genero = "Dubstep"},
New Disco With {.titulo = "d", .genero = "dubstep"}
}
Class Disco
Public titulo As String
Public genero As String
Public año As Integer
Public autor As String
Public precio As Double
Public fecha_registro As DateTime
End Class
Private Sub test() Handles MyBase.Shown
Dim currentCulture As CultureInfo = Thread.CurrentThread.CurrentCulture
Dim textInfo As TextInfo = currentCulture.TextInfo()
Dim genres As IEnumerable(Of String) =
(From disc As Disco In listaDisco
Select textInfo.ToTitleCase(disc.genero)
Distinct)
With ComboBox1
.Sorted = True
.SuspendLayout()
.Items.AddRange(genres.ToArray)
.SelectedIndex = 0
.ResumeLayout()
End With
End Sub
End Class
CSharp:using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Threading;
public class Form1
{
public static List
<Disco
> listaDisco
= new List
<Disco
> { titulo = "a",
genero = "Rock"
},
titulo = "b",
genero = "Pop"
},
titulo = "c",
genero = "Dubstep"
},
titulo = "d",
genero = "dubstep"
}
};
public class Disco
{
public string titulo;
public string genero;
public int año;
public string autor;
public double precio;
public DateTime fecha_registro;
}
private void test()
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = currentCulture.TextInfo();
IEnumerable<string> genres = (from disc in listaDiscotextInfo.ToTitleCase(disc.genero));
var _with1 = ComboBox1;
_with1.Sorted = true;
_with1.SuspendLayout();
_with1.Items.AddRange(genres.ToArray);
_with1.SelectedIndex = 0;
_with1.ResumeLayout();
}
public Form1()
{
Shown += test;
}
}
//=======================================================
//Service provided by Telerik (www.telerik.com)
//Conversion powered by NRefactory.
//=======================================================