在ListBox中显示string []数组

时间:2016-04-12 14:44:53

标签: c# arrays wpf xaml listbox

我有一个wpf ListBox,我将DataSet转换为string []数组,我试图在列表框中显示该数组,但它没有显示。

这是我的代码!!!

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;

这是我的WPF ListBox XAML代码

<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 个答案:

答案 0 :(得分:0)

以下代码使用Anugular-JS

import os.path

createDir = '\\'.join((os.path.abspath(os.path.join(os.getcwd(), os.pardir)), 'Foo'))

if not os.path.exists(createDir):
    os.makedirs(createDir)

});