I am trying to make an easy app for intern use.
And I have no clue how to make one combobox depend on other.
I have read a lot of articles but no one was clear for me.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
namespace CTSys
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
CmbGroup();
CmbTool();
}
string con = "Data Source=DESKTOP-HN7S1G3\\SQLEXPRESS;Initial Catalog=Sample;Integrated Security=true;";
// Fills tool groups
private void CmbGroup ()
{
SqlConnection sqlcon = new SqlConnection(con);
// Opens SQL Connection
try
{
sqlcon.Open();
string query = "SELECT * FROM tool_group";
SqlCommand cmd = new SqlCommand(query, sqlcon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string name = dr.GetString(1);
cmbGroup.Items.Add(name);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//Fills Tools depends on Tool Group
private void CmbTool()
{
SqlConnection sqlcon = new SqlConnection(con);
// Opens SQL Connection
try
{
sqlcon.Open();
string query = "SELECT * FROM tools";
SqlCommand cmd = new SqlCommand(query, sqlcon);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
string name = dr.GetString(2);
cmbTool.Items.Add(name);
}
sqlcon.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}