I have two tables, 1st FileFolderPath and 2nd Product_Type
FileFolderPath
`Id` `Product`
Product_Type
`Id` `Product_Id` `Product_Type` `Folder_Path`
`Product_Id` in Table Product_Type is the `Id` of FileFolderPath
In form i have below controls
[PID.Text] [comboBox2]
[PTID.Text] [comboBox3]
[PPath.Text]
---------------------------------------------------------------
"PID.Text", "comboBox2" is related to table "FileFolderPath"
"PTID.Text", "PPath.Text", "comboBox3" is related to table "Product_Type"
On form Load i made [comboBox2] populate data "Product" from Table FileFolderPath
SELECT * FROM FileFolderPath
1st Issue: when i select a `Product` from [comboBox2], i need `Id` to be filled in [PID.Text].
02nd Issue: I populated [comboBox3] on selection on [comboBox2], but i need `Id` to been filled in [PTTID.Text] and `Folder_Path` to be filled in [PPath.Text] when i select `Product_Type` from [comboBox3].
I tried several search i couldn't find a solution. So i feel this cannot be a duplication.
Kindly someone help.
Loading
Hiten PandyaPosted Sep 24, 2018, 5:44 AM
Please try the below code for filling combobox I think there might be problem in combobox filling.
Hope it helps you.
Thanks.
Hiten PandyaPosted Sep 25, 2018, 2:05 AM
Ifraz ImanudeenPosted Sep 24, 2018, 11:28 PM
Solved all my issues.
Ifraz ImanudeenPosted Sep 24, 2018, 4:15 AM
Thanks for the response.
comboBox2.SelectedValue.ToString(); doesn't seems to work.I did a void
Load_Product()
{
string da = new SqlDataAdapter("SELECT * FROM FileFolderPath",conn);
DataTable dt = new DataTable();
da.fill(dt);
for(int i = 0; i < dt.rows.count; i++)
{
string pi = dt.rows[i]["Id"].ToString() as string;
string p = dt.rows[i]["Product"]. ToString ();
comboBox2.Items.Add(p);
comboBox2.DisplayMember = p;
comboBox2.ValueMember = pi;
comboBox2.DataSource = dt;PID.Text = pi;
}
}
And in form load i mentioned Load_Product
And in comboBox2_SelectedIndexChange i mentioned PID.Text = comboBox2.SelectedValue.ToString() as string;
Still the "Id" of the "Product" from Table "FileFolderPath" is not shown in PID.Text when i select items in the Combobox
Hiten PandyaPosted Sep 24, 2018, 12:21 AM
If I understand your question correctly then,
Solution of Issue 1:
You can use the SelectedIndexChanged event of a combobox and get the
selectedvalue from combobox and just simply bind it to your textbox.
Solution of Issue 2:
You want the Id to be filled in [PTTID.Text] which you can do with selected value of combobox and for the FolderPath you can get the data in datatable and simply use select method to find the particular folderpath by passing your combobox selected value as a parameter.
see the below link to know how to use select method of datatable.
https://www.c-sharpcorner.com/UploadFile/0f68f2/querying-a-data-table-using-select-method-and-lambda-express/
https://stackoverflow.com/questions/16767010/c-sharp-datatable-select-how-do-i-format-the-filter-criteria-to-include-null
Hope it helps you.
Thanks.