처음으로 데이터 바인딩을 시도했지만 어떤 것이 작동하지 않습니다. 나는이 데이터베이스 열의 항목 목록으로 콤보 상자를 채우려고합니다. 내 데이터 집합 ds에 물건이 있음을 보여줍니다 (디버거에 표시되는 항목의 수는 약 1500이고 거기에 있어야 함). 독자와 동일한 연결 문자열을 사용하면 모든 항목을 인쇄 할 수 있습니다. 콤보 박스에 나타나야하는 것들. 콤보 상자가 비어 있지만 아이디어가 있습니까? 이제 C#내 데이터 바인딩이 작동하지 않는 이유는 무엇입니까?
DataSet ds = new DataSet();
string con_string = "user id=sql;password=pass;Server=xxx.xxx.xxx.xxx,xxxx;Database=db;Trusted_Connection=False;connection timeout=15";
string command_string = "SELECT clt FROM Client";
SqlConnection sql_con = new SqlConnection(con_string);
SqlCommand command = new SqlCommand(command_string, sql_con);
SqlDataAdapter sqlDa = new SqlDataAdapter();
sqlDa.SelectCommand = command;
sqlDa.Fill(ds);
comboBox2.DataContext = ds.Tables[0].DefaultView;
<ComboBox Height="23" HorizontalAlignment="Left" Margin="24,318,0,0" Name="comboBox2" VerticalAlignment="Top" Width="190" IsEditable="True" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding clt}" Width="100" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
그리고 모든 코드는 예외없이 실행합니다.
'combobox2.ItemsSource = ds.Tables [0] .DefaultView'를 시험해보고, 각 항목에 대한 바인딩이'clt' proeprty를 가지고 있는지 확인하고, 기본적으로 텍스트 상자에 바인딩을 시도하고 표시되는 내용을 말하십시오.'Text = "{Binding}"{ – sll