Click to See Complete Forum and Search --> : manipulating combobox


bikejokey
03-20-2006, 12:14 PM
Actually, i need to do a program using VB.NET where when the user clicks the selected items in the combobox, it will display the contets from a text file that is related to the selected item inside the combobox. The display will done in either a textbox or label. I am confused whether to use a database to store the information to be retrieved or just append a path.

For example,

the combo box contains

About LLE
LLE Algorithm
LLE source codes

The user clicks "About LLE", then when he hit the display button, the information about LLE will appear in a label or textbox.

Thanks in advanced.

sirpelidor
03-20-2006, 03:15 PM
There are many ways to do it, the simple dirty way I have off the top of my head:

3 controls: listdropbox (lstMyList), label (lblResult), and a button (btnSubmit)

first load your combo box or drop box with some value:


private void Page_Load(object sender, System.EventArgs e){
string[] myAry = {"About LLE","LLE Algorithm","LLE source codes"}
lstMyList.DataSource = myAry;
this.DataBind();
}//end page_load


then, on submit check which item has been selected on ur list box:


private void btnSubmit_Click(object sender, System.EventArgs e)
{
if (lstMyList.SelectedValue == "About LLE")
lblResult.text = "put your text here";
else if (lstMyList.SelectedValue == "LLE Algorithm")
lblResult.text = "put your text here";
else if (lstMyList.SelectedValue == "LLE source codes")
lblResult.text = "put your text here";
else
lblResult.text = "";
}


hope you learned few things here:

1) lstMyList.SelectedValue is the item user picked
2) lblResult's content can change dymacically
3) btnSubmit_Click only fire when button is click
4) lstMyList.DataSource = myAry; allows you to load ur value from code behind
5) this.DataBind(); allows you to bind any data driven control

bikejokey
03-21-2006, 04:35 AM
Dear Sepelidor,
I would like to thank you so much for the codes u have gaven me but i still have some problem at the string and "this" part.
string[] myAry = {"About LLE","LLE Algorithm","LLE source codes"}
lstMyList.DataSource = myAry;
this.DataBind();

When building , it says that "string is a class type and cannot be used an an expression".
Do u have any other alternative?
thanks in advanced.

sirpelidor
03-21-2006, 06:02 AM
i still have some problem at the string and "this" part.
string[] myAry = {"About LLE","LLE Algorithm","LLE source codes"}
lstMyList.DataSource = myAry;
this.DataBind();


I'm sorry that I am very sloopy with my syntax, My main goal here is to help get you start thinking of a logical approach instead of giving you free code, I figure one won't learn anything if someone else kept hand stuff to him.

you need that ; at the end of string statement, that's basic c# syntax.