我在使用gridview和組合框內的一些問題。在GridView中填充組合框
這裏是我的ListView控件的代碼:
<ListView Height="139" HorizontalAlignment="Left" Margin="10,158,0,0" Name="lvAppointment" VerticalAlignment="Top" Width="250" MinWidth="350">
<ListView.View>
<GridView>
<GridViewColumn Header="Appointment" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate>
<DatePicker SelectedDate="{Binding Path=Appointment}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Type" Width="170">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox ???/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Done" Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path=Done}" IsThreeState="False"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
我從SQL CE數據庫通過C#與下面的代碼
using (SqlCeCommand sqlCeAppointment = new SqlCeCommand("SELECT appid,appointment,done,apptype.type FROM appointment INNER JOIN apptype ON appointment.refatid = apptype.atid WHERE refeventid = @eventid;", sqlCeConn))
{
sqlCeAppointment.Parameters.AddWithValue("@eventid", ((cListEventItem)lvEvent.SelectedItems[0]).id);
using (SqlCeDataReader sqlCeAppointmentReader = sqlCeAppointment.ExecuteReader())
{
lvAppointment.Items.Clear();
while (sqlCeAppointmentReader.Read())
{
lvAppointment.Items.Add(new cListAppointmentItem { id = sqlCeAppointmentReader.GetGuid(sqlCeTerminReader.GetOrdinal("appid")), Appointment = sqlCeAppointmentReader.GetDateTime(sqlCeTerminReader.GetOrdinal("appointment")), Type = sqlCeAppointmentReader.GetString(sqlCeTerminReader.GetOrdinal("type")), Done = sqlCeAppointmentReader.GetByte(sqlCeTerminReader.GetOrdinal("done")) });
}
}
}
我可以popluating列表突出顯示列表。但我想要「類型」是一個組合框,所以用戶可以選擇適當的約會類型(其約會連接到一個事件的列表)。這個組合框應該填充sql數據庫(apptype)表內的數據。該表格不是靜態的,用戶可以從該列表添加和刪除項目。
我嘗試了幾種方法,我通過谷歌發現,但失敗了。我想我有問題了解如何工作/應該工作。
我希望有人能幫助我:(
在此先感謝