ここではWPFが新しくなりました。私は、シーンを設定します: 私はこのような何かと費用のリストとリストビュー持っている:ListViewにコンボボックスの列を設定する
- 経費説明:スーパーマーケットのショッピング
- 経費日:2017年2月3日
- 費用を金額:$ 50
- 経費タイプ:食料品
経費タイプは私のDBに別々のテーブルに格納されており、外部キーexpense_type_id経由費にリンクされています。
費用の種類がない費用のリストを取得しようとしています。オプションのリスト(費用タイプテーブルのデータ)から費用タイプを設定できるようにしています。
これを行うには、expense_type_idなしで費用を保持するListViewを作成しました。
<ListView x:Name="lvAllocation" HorizontalAlignment="Left" Height="475" Margin="0,44,0,0" VerticalAlignment="Top" Width="1308" FontSize="16">
<ListView.View>
<GridView>
<GridViewColumn Header="Posted" Width="120" DisplayMemberBinding="{Binding ex_posted_date}" />
<GridViewColumn Header="Trans" Width="120" DisplayMemberBinding="{Binding ex_trans_date}" />
<GridViewColumn Header="Description" Width="120" DisplayMemberBinding="{Binding ex_description}" />
<GridViewColumn Header="Amount" Width="120" DisplayMemberBinding="{Binding ex_amount}" />
<GridViewColumn Header="Expense Type" x:Name ="cmbExpenseType" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=IC_NAME }" Width="120" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
以上は、リストビューの詳細なWPFです。入力するコードは次のとおりです。
Private Sub SetupAllocationTab()
'Get list from DB (where there isn't an expense type)
Dim queryExceptions =
From expense In dataEntities.expenses
Where expense.expense_type.ex_type_desc Is Nothing
Order By expense.ex_posted_date
Select
expense.ex_id,
expense.ex_type_id,
expense.override_ex_type_id,
expense.month_id,
expense.account_id,
expense.ex_posted_date,
expense.ex_trans_date,
expense.ex_description,
expense.ex_amount,
expense.ex_deduction,
expense.notes,
expense.ex_file_desc,
expense.insert_datetime,
expense.insert_user,
expense.insert_process,
expense.update_datetime,
expense.update_user,
expense.update_process
'For each item, make an expense object and add it to the ListView
For Each item In queryExceptions.ToList
Dim exp = New expense(item.ex_id, item.ex_type_id, item.override_ex_type_id, item.month_id, item.account_id, item.ex_posted_date, item.ex_trans_date, item.ex_description, item.ex_amount,
item.ex_deduction, item.notes, item.ex_file_desc, item.insert_datetime, item.insert_user, item.insert_process, item.update_datetime, item.update_user, item.update_process)
lvAllocation.Items.Add(exp)
Next
'Create list for expense dropdown
ExceptionTypeDropdown()
End Sub
私のデータベースから取得したedmxデータモデルを実行しています。
私の質問は、Expense_typeテーブルにあるdatでComboBox列を設定する方法です。これは私がオンラインで見つけたいくつかのことを試してみる限りです。どんな助けでも大歓迎です。
Private Sub ExceptionTypeDropdown()
Dim expenseTypes =
From expense_type In dataEntities.expense_type
Select expense_type.ex_type_code,
expense_type.ex_type_desc
'Add the expense type combo box on the DataGrid
End Sub