コード例 #1
0
        private void Search_TextChanged(object sender, TextChangedEventArgs e)
        {
            string S_key = Search.Text;

            try
            {
                if (S_key == "")
                {
                    invLoadGrid();
                }
                else
                {
                    DataTable dt = new DataTable();
                    con = new SqlConnection(ConfigurationManager.ConnectionStrings["conString"].ConnectionString);
                    con.Open();
                    SqlDataAdapter sda = new SqlDataAdapter(
                        "SELECT ingredient, unit FROM inventory WHERE ingredient LIKE'%" + S_key + "%';", con);
                    sda.Fill(dt);
                    InventoryItemDataGrid.SetBinding(ItemsControl.ItemsSourceProperty, new Binding {
                        Source = dt
                    });
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.ToString(), "Info");
            }
            finally
            {
                con.Close();
            }
        }
コード例 #2
0
        private void invLoadGrid()
        {
            DataTable invDataTable = InvItem.InventoryDataTable();

            InventoryItemDataGrid.SetBinding(ItemsControl.ItemsSourceProperty, new Binding {
                Source = invDataTable
            });
        }