How can i display textbox values based on combobox selected value(windows applicaitons)?

Posted by Sudheep.grandhe under C# on 12/1/2011 | Points: 10 | Views : 9824 | Status : [Member] | Replies : 2
Hi,

I was designed a windows application form named as updatecustomerinvoice.in this form my issue is.with the name of companyname combobox is there if i choose any companyname name from combobox(cmb_companyname).it has to display the remaining textboxes.i will display my tables here.
Tbl_report1 columns:
Invoiceno,particulars,quantity,perprice,amount,invoicedate,ondate,invoiceid,orderno
Tbl_report2 columns:
Compname,compaddress,invoiceno(primarykey),orderno,ondate,invoicedate,amountstatus,netamount,netvat,tamount
Tbl_customer columns:
Custid,custname,custaddress,custcity,custstate,custstdcode,custphoneno,custmobileno

in my form I am having these fields like I mentioned above two tables.my issue is if I select the compname it should display the remaining fields.for loading only companynames I wrote the code is below.
private void loadcompanies()
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand("select '0' as compaddress,'selectone' as compname union select compaddress,compname from dbo.tbl_report2 ", con);//I am using here customer table.for this reason only it shows customer address itself.can you please correct this for getting all fields.
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
if (con.State == ConnectionState.Closed)
{
con.Open();
}
da.Fill(dt);
cmb_companyname.DataSource = dt;
cmb_companyname.DisplayMember = "compname";
cmb_companyname.ValueMember = "compaddress";
}
But it shows the customeraddressonly.for that I wrote the code in selectedindexchangedevent.
private void cmb_companyname_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=marsweb;integrated security=true");
SqlCommand cmd = new SqlCommand("select t2.compaddress,t1.invoiceno,t1.orderno,t1.ondate,t1.particulars,t1.perprice,t1.amount,t2.netvat,t2.tamount,t2.netamount from tbl_report2 t2,tbl_report1 t1 where t1.compname='hdfcbank' and t2.compname='hdfcbank'", con);
//SqlCommand cmd = new SqlCommand("select custaddress from tbl_customer where custname=@custname", con);
//cmd.Parameters.AddWithValue("@custname",cmb_companyname .Text );
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
txt_customeraddress.Text = cmb_companyname.SelectedValue.ToString();
//txt_orderno.Text = cmb_companyname.SelectedValue.ToString();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
txt_customeraddress .Text =dt .Rows [0]["customeraddress"].ToString ();
//txt_customeraddress.Text = dt.Rows[0][0].ToString();
txt_invoiceno.Text = dt.Rows[0][1].ToString();
txt_orderno.Text = dt.Rows[0][2].ToString();
txt_ondate.Text = dt.Rows[0][3].ToString();
cmb_particulars.Text = dt.Rows[0][4].ToString();
txt_quantity.Text = dt.Rows[0][5].ToString();
txt_perprice.Text = dt.Rows[0][6].ToString();
txt_amount.Text = dt.Rows[0][7].ToString();
txt_vat.Text = dt.Rows[0][8].ToString();
txt_totalamount.Text = dt.Rows[0][9].ToString();
txt_netamount.Text = dt.Rows[0][10].ToString();
}

}
}

Best,
Sudheep.



Responses

Posted by: Naraayanan on: 1/6/2012 [Member] Starter | Points: 25

Up
0
Down
hi,
try this way:

First Fill the data in the ComboBox.
second paste this code in combobox SelectedIndexChanged Event
textBox1.Text = comboBox1.Text;

(your textbox name) = your comboboxname)


Regards,
Lakshmi Naraayanan.S
http://dotnettechrocks.blogspot.in/
http://abaprocker.blogspot.com/

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 1/6/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,

I want to update the gridview data .Here is my requirment the user enter the details it will be displayed in the gridview .in gridview itself i want to update the data and viceversa delete also.how can i do this.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response