mohammad5530
سه شنبه 20 فروردین 1392, 23:06 عصر
سلام
من توی فرمم یک کومبو باکس و یک گریدویو دارم.
کومبو باکس از دیتابیس یکسری اطلاعات میگیره و نشون میده
حالا من میخام توسط یک کد نوشته ی داخل کومبو باکس داخل گرید ویو نمایش داده بشه
لطفا کمک کنید
khokhan
سه شنبه 20 فروردین 1392, 23:53 عصر
سلام
فرض می کنیم با این کد کمبو رو پرکردیم
SqlConnection cn = new SqlConnection("data source=localhost;initial catalog=acc;uid=sa;pwd=emotions");
private void Form1_Load(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select ClassId, Class from Class order by ClassId", cn);
DataTable dt = new DataTable();
da.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "Class";
comboBox1.ValueMember = "ClassId";
بعد می آیی در رویداد SelectionChangeCommitted کمبو باکس می نویسی :
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select SNAme, FName, SPhoneNo from Students where ClassId =" + comboBox1.SelectedValue, cn);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
}
mohammad5530
چهارشنبه 21 فروردین 1392, 00:04 صبح
میشه از طریق linq توضیح بدید؟
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.