TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Marco Rodríguez
NA
8
506
Cascade ComboBox depends on first one
Nov 6 2017 9:50 AM
Hello I got a problem.
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.
I guess I started totally wrong.
Here is my code:
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);
}
}
}
}
Reply
Answers (
1
)
calling url with its credentials and want to pass the file
About retrieving images from SQL to datagridview