i want to add search panel in my datagrid, there is no error in code but if i enter any value it is not showing any output. Can you please answer my question. my code is here below:
<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 have attached image of it too! Thank You !