1. 程式人生 > 其它 >下拉框改變並繫結相關資訊操作

下拉框改變並繫結相關資訊操作

技術標籤:WPFC#SQL

需要完成功能:

選中客戶下拉框,繫結聯絡人、涼蓆電話、交貨地點三個文字框的值。

分析:

  1. 先繫結好客戶下拉框的值:(事先定義好全域性變數 DataTable kh
//客戶 kh = myKh.Window_Loaded_SelectClient().Tables[0];

 cbo_client.ItemsSource = kh.DefaultView;

 cbo_client.DisplayMemberPath = "clientName";

 cbo_client.SelectedValuePath = "clientFileID";

  1. 再給客戶下拉框加一個SelectionChanged 事件:
<TextBlock Grid.Row="1" Grid.Column="1" Text="客 戶:" Margin="10,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>

<ComboBox Grid.Row="1" Grid.Column="2" x:Name="cbo_client" Width="162" SelectionChanged="cbo_client_SelectionChanged"/>

  1. 再到下拉框改變事件中編寫相關程式碼
//客戶下拉框改變事件

 private void cbo_client_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)

 {

 if (Convert.ToInt32(cbo_client.SelectedValue) != 0)

 {

 txt_address.Text = kh.Rows[0]["area"].ToString();

txt_phone.Text = kh.Rows[0]["cellphone"].ToString(); txt_content.Text = kh.Rows[0]["contact"].ToString();

 }

 }

  1. Sql這邊的程式碼如下:
if(@type='Window_Loaded_SelectClient')

begin

SELECT ROW_NUMBER() over(order by t_clientFile.clientFileID)asxuHao,

t_clientFile.clientFileID, t_provideClient.contact, t_provideClient.phone,

t_provideClient.fax, t_provideClient.zipCode, t_provideClient.address, t_clientFile.clientNumber, t_clientFile.dealNum, t_clientFile.clientName,

t_clientFile.cellphone,t_clientFile.area, t_clientFile.wholesalePrice, t_clientFile.wholesaleDisCount, t_clientFile.bookBuilder_id, t_operators.name, t_clientFile.lockOrNo, t_clientFile.effectiveDay, t_clientFile.updateDay, t_clientFile.mode, t_clientFile.startSum, t_clientFile.jk_Type, t_clientFile.jz_date, t_clientFile.yp_batch, t_clientFile.js_cycle,

t_clientFile.note, t_bankAccount.account

FROM

 t_clientFile INNER JOIN

t_provideClient ON t_clientFile.provideClientID = t_provideClient.provideClientID INNER JOIN

t_bankAccount ON t_clientFile.bankAccountID = t_bankAccount.bankAccountID INNER JOIN

 t_operators ON t_clientFile.bookBuilder_id = t_operators.operator_id

end

圈圈內的是改變下拉框繫結相關資料的三個文字框的值,下劃線的就是繫結客戶下拉框的選中值和顯示值。