ListBox에 X 항목이 있습니다. Item은 String, double, double처럼 구성됩니다. 두 번째 double의 값이 smalles 인 항목이 레이블에 문자열과 함께 표시되기를 원합니다.ListBox 항목에서 단일 문자열 가져 오기
예제 항목 : 이름 값 1 값 2 모든 부분은 공백으로 구분됩니다. 이 코드는 두 번째 double의 최소값을 가져 오는 데만 작동하지만 해당 항목의 문자열을 가져 오지 않습니다.
vName의 기능이 작동하지 않습니다.
private void bVergleich_Click(object sender, RoutedEventArgs e)
{
if (listBox.Items.Count <= 0)
{
MessageBox.Show("Bitte erst Einträge hinzufügen.");
}
else
{
int anzahl = listBox.Items.Count;
string str = listBox.Items[anzahl].ToString();
string vName = str.Substring(0, str.IndexOf(" ") + 1);
var numbers = listBox.Items.Cast<string>().Select(obj => decimal.Parse(obj.Split(' ').First(), NumberStyles.Currency, CultureInfo.CurrentCulture));
decimal minValue = listBox.Items.Cast<string>().Select(obj => decimal.Parse(obj.Split(' ').Last(), NumberStyles.Currency, CultureInfo.CurrentCulture)).Min();
lVergleich.Content = vName + " " + minValue + "€";
}
}
어떻게 문자열을 얻을 수 있습니까?
ListBox 항목의 문자열 대신 MSDN의 [데이터 템플릿 개요] (https://msdn.microsoft.com/en-us/library/ms742521(v=vs.100) .aspx) 문서를 살펴보십시오. – Clemens
귀하의 가치 (두 번째 두 번째)가 뚜렷하지 않거나? =! –
@Clemens는 데이터 템플릿을 사용하는 것 외에 다른 아이디어가 있습니까? –