mardi 26 avril 2016

WPF XAML database driven checkbox values

how do I display an unknown number of checkboxes in XAML? I'm querying the database to extract a list of possible values, and then I want to display those values as a list of checkboxes. Some DB tables may have a small number of values, others could potentially have 100+.

XAML:

<ListBox x:Name="SuppliersSearchStatusListBox" Margin="100,100,0,0" ScrollViewer.CanContentScroll="True" AllowDrop="True" MaxHeight="50" MaxWidth="200" HorizontalAlignment="Left" VerticalAlignment="Top" ItemsSource="{Binding ListStatusOptions}">
  <CheckBox Content="{Binding arrStatusOption}"/>
</ListBox>

CS:

public void ListStatusOptions()
{
    // Query, vars and debug info removed
    conn.Open();
    SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQLQuery, conn);
    DataSet ds = new DataSet();
    dataAdapter.Fill(ds, "StatusOptions");

    int varArrCount = ds.Tables[0].Rows.Count;

    string[] arrStatusOption = new string[varArrCount];
    int i = 0;
    foreach (DataRow dr in ds.Tables[0].Rows)
    {
        arrStatusOption[i] = dr["StatusValue"].ToString();
        i++;
    }
    conn.Close();
}

The DB query returns results into the array and the values are as expected, but a list of checkboxes do not appear on the XAML page. What am I missing?




Aucun commentaire:

Enregistrer un commentaire