listbox coding

yogesh lingayat

New member
Joined
Jun 22, 2011
Messages
3
Programming Experience
Beginner
Hi

how compare the selected item of the listbox with the database and dispaly data again in the textbox of front end please replay immegiatly

from yogesh lingayat

:confused::confused::confused::confused:
 
Last edited:
how compare the selected item of the listbox with the database and dispaly data again in the textbox of front end

your question seems a bit vague? Can you elaborate a bit? How are you reading the data from your database, and what is this "textbox of front end" you speak of?

To get the selected item of a listbox you can try using the selectedItem property, like

ListBox1.SelectedItem
'another way is to get it from the Items collection using an index, like:
ListBox1.Items(ListBox1.SelectedIndex)


Here's some reference on MSDN about the Listbox that may help
ListBox.Items Property (System.Windows.Forms)
ListBox Class (System.Windows.Forms)
 
i like this coding but if i use this code then only selected item of listbox will display

like

eg: textbox1.text = listbox1.SelectedItem

but i want suppose my backend contain field emp_id,emp_name and other detail then in front end i have design text box for that fields and i am adding record in database using front end add button and textbox1.text is the emp_id then value of textbox1 want to display in listbox1 for that i have done coding listbox1.Items.Add(textbox1.text) then whatever emp_id add in textbox that inserted in backend also and in listbox also then i clear textboxes using textbox1.text = "" method then again add second record using add button then when i click the listbox1 item that is first item then selected item want to match with database and other detail of that selected item(emp_id) should display again in textbox so which object i take to reffer database like we do in vb


Dim rs As ADODB.Recordset

textbox1.text = rs.Field(0)

like this tell me the coding in vb.net
 

Attachments

  • bpo software.zip
    33 KB · Views: 21
Last edited by a moderator:
selected item want to match with database and other detail of that selected item(emp_id) should display again in textbox so which object i take to reffer database like we do in vb

Dim rs As ADODB.Recordset

textbox1.text = rs.Field(0)

I am sorry, i can barley understand what you wrote, (i took a quick look at your bpo software solution, but i dont have time to go through it) but i think i got an idea of what your trying to do?

Basically, you want your listbox to be filled with data from a column of a table from an database. When an item is selected on the listbox you want the corresponding data from a different column of the same row to show up in the textbox, right?

Here's an example i found online from a site i like that has a lot of working code examples. Bind data to ListBox : Data bind to ListBox*«*Database ADO.net*«*VB.Net (i think this is what you want to do?)

if you do not want to bind the data members to the textboxes and you want to do it on a button click or when the selected index is changed you can do something like...
    'instead of binding like:
    'TextBox1.DataBindings.Add("text", dt, "COLUMNNAME")

    'in the selectedindexchanged or other event you can do something like: 
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Dim drv = CType(ListBox1.SelectedItem(), DataRowView) 'note that in order for this to work the items in the listbox should be of type DataRowView, which is what would happen if you set the listbox DataSource property to a DataTable like shown in the example in the link above
        TextBox1.Text = drv.Row("COLUMNNAME").ToString()
    End Sub


hope that helps... I don't know too much about the database aspect, if you have more questions with regards to databases maybe someone else on here can help you. if it is more aimed toward databases maybe you can also try posting in the Database Topic or such Database General Discussion rather than the Windows Forms.
 
Last edited:
Back
Top