2013-06-30 6 views
0

내 데이터 격자에 검색 패널을 추가하고 코드에 오류가 없지만 값을 입력해도 결과가 표시되지 않습니다. 내 질문에 대답 해 주실 수 있겠습니까? 나도 그것의 이미지를 첨부검색 패널 오류

 <Window x:Class="WpfApplication3.MainWindow" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" 
      dx:ThemeManager.ThemeName="MetropolisDark" 
      Title="MainWindow" Height="350" Width="525" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      ResizeMode="CanMinimize" mc:Ignorable="d" Loaded="Window_Loaded" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"> 


      <Grid Background="#FF333333" > 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto" /> 
       <RowDefinition Height="*"/> 
       <RowDefinition Height="Auto"/> 
      </Grid.RowDefinitions> 

      <TextBlock Grid.Row="1" Height="28" HorizontalAlignment="Left" Margin="41,12,0,0" x:Name="textBlock1" Text="Type here" VerticalAlignment="Top" Width="71" /> 
      <TextBox Grid.Row="1" HorizontalAlignment="Left" Margin="139,12,0,246" x:Name="textBox1" Width="233" TextWrapping="NoWrap" TextChanged="textBox1_TextChanged" /> 
      <ListBox Grid.Row="1" Background="LightYellow" Visibility="Collapsed" Height="33" HorizontalAlignment="Left" Margin="220,45,0,0" Name="listBox1" VerticalAlignment="Top" Width="202" /> 
     </Grid> 
</Window> 
 public partial class MainWindow : Window 
    { 
     //object used for update data 
     DataClasses1DataContext objContext = new DataClasses1DataContext(); 
     //object used to update selected row data 
     Assignment student = null; 
     IEnumerable eventt_grp1; 
     public MainWindow() 
     { 
      InitializeComponent(); 
       //Database context 
       //StudentDBDataContext objContext = new StudentDBDataContext(); 

       //Linq to SQL: this is like sql select query 
       //std is table alias 
       //objContext.StudentDetails is table from data is seleted 
       //var result: behaves like DataSet/DataTable 
       List<Assignment> a = new List<Assignment>(); 

       eventt_grp1 = a.Select(r => new { r.assignment_title }).ToList(); 

       textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged); 

       //Show message if it has rows 


     } 

     private void textBox1_TextChanged(object sender, TextChangedEventArgs e) 
     { 

    string typedstring= textBox1.Text; 
List<string> autolist= new List<string>(); 
foreach(string b in eventt_grp1) 
{ 
if(!string.IsNullOrEmpty(textBox1.Text)) 
{ 
if(b.StartsWith(typedstring)) 
{ 
autolist.Add(b); 
} 
} 
} 
if(autolist.Count>0) 
{ 
    listBox1.ItemsSource = autolist; 
    listBox1.Visibility = Visibility.Visible; 

} 
else if (textBox1.Text.Equals ("")) 
{ 

    listBox1.Visibility = Visibility.Collapsed; 
    listBox1.ItemsSource = null; 
} 

else 
{ 

    listBox1.Visibility = Visibility.Collapsed; 
    listBox1.ItemsSource = null; 
} 


     } 

     private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) 
     { 

      if (listBox1.ItemsSource != null) 
      { 
       listBox1.Visibility = Visibility.Collapsed; 
       textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged); 
      } 

      if (listBox1.SelectedIndex != -1) 
      { 
       textBox1.Text = listBox1.SelectedItem.ToString(); 
       textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged); 
      } 
     } 

i : 내 코드는 아래에 여기! 고맙습니다 !

+3

사용중인 소프트웨어를 구입하십시오. –

답변

0

흐름을 디버깅하는 것이 좋습니다. 자동 작성자가 비어있을 수도 있습니다. 또한 데이터 소스를 업데이트하려면이 옵션을 사용

listBox1.DataSource = null; 

listBox1.DataSource = myList; 

편집 도움이되기를 바랍니다 : 힌트 -> 형식 코드를!