2016-04-12 24 views
0

Bir wpf ListBox'um var, DataSet'i string [] dizisine dönüştürdüm ve diziyi liste kutusunda görüntülemeye çalışıyorum ancak görüntülenmiyor.Liste Kutusu [] dizisini bir ListBox

Bu benim Kuralım !!!

string query = " SELECT category_id, category_name, amount FROM acc_income_category WHERE deleted = 0 ORDER BY category_name ASC "; 
da = new SQLiteDataAdapter(query, con); 
ds = new DataSet(); 
da.Fill(ds, "acc_income_category"); 
string[] arr = new string[ds.Tables[0].Rows.Count]; 
for (int i = 0; i < ds.Tables[0].Rows.Count; i++) 
{ 
    arr[i] = ds.Tables[0].Rows[i]["category_name"].ToString(); 
} 
ListBox_Category_Names.ItemsSource = arr; 

Ve bu Anugular-JS kullanarak çalışıyor kod parçasını ardından benim WPF ListBox XAML Kod

<ListBox x:Name="ListBox_Category_Names" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
    Width="auto" Height="auto" SelectionMode="Multiple" ItemsSource="{Binding acc_income_category}" Grid.Row="1" > 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <Grid HorizontalAlignment="Stretch" > 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="auto" /> 
        <ColumnDefinition Width="*" /> 
        <ColumnDefinition Width="auto" /> 
       </Grid.ColumnDefinitions> 
       <CheckBox x:Name="chkBox_CheckCategory" Grid.Column="0" Width="35" Height="35" Cursor="Hand" IsChecked="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem}, Path=IsSelected}" /> 

       <!--<TextBlock Text="{Binding category_name}" Grid.Column="1" FontSize="15" Foreground="#FF666666" Margin="10,0,5,0" VerticalAlignment="Center" HorizontalAlignment="Left" /> 
       <TextBlock Text="{Binding amount, ConverterCulture=ig-NG, StringFormat=\{0:C\}}" Grid.Column="3" FontSize="15" Foreground="#FF666666" Margin="5,0,5,0" VerticalAlignment="Center" HorizontalAlignment="Stretch"/>--> 

      </Grid> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
+1

Dize dizisi neden? Bağlama kullanın, bkz: http://stackoverflow.com/questions/12363369/how-can-i-bind-a-listbox-to-a-data-table-in-wpf-applications –

+0

Sadece kullanırsanız ne olur? '.ToList()' ListBox 'ListBox_Category_Names.ItemsSource = arr.ToList();' bazı stackoverflow örnekleri için aşağıdakiler için googling'i deneyin: C# stackoverflow Listeleme Bağlama Listbox 'yapmak için birçok yol vardır Bu – MethodMan

+0

https://msdn.microsoft.com/en-us/library/aa480224.aspx –

cevap

0

olduğunu

var USState = ["Alabama", "Alaska" , "Arizona" ,"Arkansas", "California", 
     "Colorado", "Connecticut"]; 

$(document).ready(function() 
{ 
stateselect = document.getElementById("state"); 
for(i=0; i < USState.length; ++i) 
{ 
    var el=document.createElement('option'); 
    el.textContent = USState[i]; 
    stateselect.appendChild(el); 
} 

});

İlgili konular