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
Ifraz Imanudeen
NA
60
3.1k
Multi Column ComboBox but when Selecte Value should be Id
Sep 7 2018 8:27 PM
Hi everyone,
i have the done following coding, unable to get the it working..
i have a Table with Id, Product, FolderPath.
i have a comboBox2 where i need two column of data from above table "Id" & "Product" to been shown in comboBox2. Now if i select a Row from comboBox2 i need the textBox1 and textBox2 to be filled with "Product" and "FolderPath" based on the comboBox2 selection.
Like even though the comboBox2 shows "Id" & "Product" internally the value has to be "Id".
Following are my code; can someone help me on this.
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Data.SqlClient;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Windows.Forms;
using
System.IO;
namespace
WindowsFormsApp1
{
public
partial
class
Main : Form
{
string
connString;
SqlConnection conn;
public
Main()
{
InitializeComponent();
}
private
void
Main_Load(
object
sender, EventArgs e)
{
connString = @
"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=ifz001;"
;
conn =
new
SqlConnection(connString);
conn.Open();
Load_Products();
}
void
Load_Products()
{
try
{
SqlDataAdapter da =
new
SqlDataAdapter(
"SELECT * FROM FileFolderPath"
, conn);
DataTable dt =
new
DataTable();
da.Fill(dt);
for
(
int
i = 0; i < dt.Rows.Count; i++)
{
comboBox2.Items.Add(dt.Rows[i][
"Id"
].ToString() + " | " + dt.Rows[i][
"Product"
].ToString());
comboBox2.ValueMember = dt.Rows[i][
"Id"
].ToString();
}
}
catch
(Exception lp)
{
MessageBox.Show(lp.Message);
}
}
private
void
comboBox2_SelectedIndexChanged(
object
sender, EventArgs e)
{
/*try
{*/
var pix =
"SELECT * FROM FileFolderPath WHERE Id = '"
+ comboBox2.ValueMember +
"'"
;
SqlCommand cmd =
new
SqlCommand(pix, conn);
cmd.ExecuteNonQuery();
DataTable dt =
new
DataTable();
SqlDataAdapter da =
new
SqlDataAdapter(cmd);
da.Fill(dt);
foreach
(DataRow dr
in
dt.Rows)
{
PID.Text = dr[
"Product"
].ToString();
PPath.Text = dr[
"FolderPath"
].ToString();
}
/*}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}*/
}
Reply
Answers (
1
)
how read a phone number from text or pdffile using csharp
the breakpoint is not currently be hit vs2017