PDA

View Full Version : دو ستونه کردن ComboBox



asghar2008
جمعه 13 بهمن 1391, 21:02 عصر
سلام

دوستان میخوام کمبوباکس رو دوستونه کنم .

دلیل این کار اینکه میخوام از دیتابیس 2 فیلدانتخاب کرده و در کمبو باکس بریزم.

چطور میتونم این کارو انجام بدم؟

ممنون

khokhan
جمعه 13 بهمن 1391, 21:08 عصر
سلام

دوستان میخوام کمبوباکس رو دوستونه کنم .

دلیل این کار اینکه میخوام از دیتابیس 2 فیلدانتخاب کرده و در کمبو باکس بریزم.

چطور میتونم این کارو انجام بدم؟

ممنون


http://www.codeproject.com/Articles/3206/Multi-Column-ComboBox

ordebehesht
جمعه 13 بهمن 1391, 21:47 عصر
حالا چطور به بانک باین کنیم

khokhan
جمعه 13 بهمن 1391, 22:48 عصر
حالا چطور به بانک باین کنیم

خیلی راحت :لبخند:


public void getList()
{
// set the connectionstring for the database
SqlConnection con = new SqlConnection();
try
{
//before adding records in combobox clear previous data
cmbMemberName.Items.Clear();
// define the sql query that should we want to perform
con.ConnectionString = "Data Source=INDIA\\SQLEXPRESS;Initial Catalog=test;Integrated Security=True";
// define the sql query that should we want to perform
string query = "select member_id,member_name,member_email from Member_Master";
//create object of Sqlcommand class and pass two parameters sqlserver query and sqlconnection con
SqlCommand cmd = new SqlCommand(query, con);
//set the commandtext to query
cmd.CommandText = query;
//before perform sql operation open the connection
con.Open();
//execute the ExecuteReader
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
//add item by item in combobox
cmbMemberName.Items.Add(dr["member_id"].ToString() + " " + dr["member_name"].ToString() + " " + dr["member_email"].ToString());
}
}
catch
{
MessageBox.Show("Error in Connection");
}
//close the connection
con.Close();
}

ordebehesht
جمعه 13 بهمن 1391, 23:21 عصر
میشه تو بلاک C# بزاری

asghar2008
جمعه 13 بهمن 1391, 23:24 عصر
مرسی دوست عزیز
ساقول .

فقط یه سوالم داشتم وقتی کاربر یه ردیف رو انتخاب میکنه میشه به یه مقدار از ستون اول دسترسی داشت؟
منظورم مثلا:
ستون اول
سطر 5

ممنون

ordebehesht
جمعه 13 بهمن 1391, 23:30 عصر
asghar gardash haralisan

sanda tork san