how do you bind a bindingsource created on class to a textbox?
i want to bind a specific field, but i dont know how because database is retrieve at runtime.
binding source, how to bind?
Page 1 of 16 Replies - 59252 Views - Last Post: 27 January 2008 - 02:04 AM
Replies To: binding source, how to bind?
#2
Re: binding source, how to bind?
Posted 15 August 2007 - 05:17 AM
To bind a single item in the BindingSource to a TextBox use this
Of course replace YourBindingSource with the name of your BindingSource Object, and YourFieldName with the name of the field you're looking for.
If there are multiple records returned and you have multiple textboxes to fill then do it in a loop (doing it this way your textboxes should be names YourName_1, YourName_2, etc...)
This should at least get you started in the right direction
Happy Coding!
TextBox1.Text = YourBindingSource("YourFieldName").ToString
Of course replace YourBindingSource with the name of your BindingSource Object, and YourFieldName with the name of the field you're looking for.
If there are multiple records returned and you have multiple textboxes to fill then do it in a loop (doing it this way your textboxes should be names YourName_1, YourName_2, etc...)
For i As Integer = 0 To YourBindingSource.Count - 1
TextBox_ & i & .Text = YourBindingSource(i)("YourFieldName").ToString
Next
This should at least get you started in the right direction
Happy Coding!
#3
Re: binding source, how to bind?
Posted 17 August 2007 - 08:31 PM
Hi,
i get errors
"conversion from string "Username" to type integer is not valid.
my line of code
mytextbox.text = mybindingsource("Username").tostring
i get errors
"conversion from string "Username" to type integer is not valid.
my line of code
mytextbox.text = mybindingsource("Username").tostring
#4
Re: binding source, how to bind?
Posted 17 August 2007 - 08:42 PM
Try this
Doing this you're using the DataBindings property of the control to pull the username value from the bindingsource object. Hope this helps
Happy Coding!
TextBox1.DataBindings.Add("Text",MyBindingSource,"Username")
Doing this you're using the DataBindings property of the control to pull the username value from the bindingsource object. Hope this helps
Happy Coding!
#5
Re: binding source, how to bind?
Posted 17 August 2007 - 09:04 PM
it works... thank you sir
#6
Re: binding source, how to bind?
Posted 17 August 2007 - 09:04 PM
No problem cimpercee, thats what we're here for
Glad I could help 
<edit>No need to call me sir
</edit>
<edit>No need to call me sir
This post has been edited by PsychoCoder: 17 August 2007 - 09:05 PM
#7
Re: binding source, how to bind?
Posted 27 January 2008 - 02:04 AM
hi
i would like to make binding to only the field that i search by
and here is my search code
and here is my binding
its binding succsefully but what i want is to only binding the data that comes from my search
i would like to make binding to only the field that i search by
and here is my search code
If RadioButton1.Checked = True Then
If nametext.Text = "" Then
MsgBox("خطاء في البحث !! الرجاء ادخال اسم الموظف")
Call cancel()
Call clear()
Else
SqlCommand4.Parameters("@tech_name").Value = nametext.Text
Dim read As SqlClient.SqlDataReader
SqlConnection1.Open()
read = SqlCommand4.ExecuteReader
If Not read.Read Then
MsgBox("الاسم غير موجود")
read.Close()
SqlConnection1.Close()
Call cancel()
Call clear()
Else
TextBox1.Text = read.Item("id")
nametext.Text = read.Item("tech_name")
ComboBox1.Text = read.Item("tech_sec")
ComboBox2.Text = read.Item("tech_level")
usertext.Text = read.Item("tech_user_name")
passtext.Text = read.Item("tech_password")
pass1text.Text = read.Item("tech_rpassword")
ComboBox3.Text = read.Item("user_type")
read.Close()
SqlConnection1.Close()
End If
End If
End If
and here is my binding
Dim ds As New DataSet
Dim da As New SqlDataAdapter
Dim bind As New BindingSource
Private Sub Users_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SqlConnection1.Open()
da = New SqlDataAdapter("select * from client", SqlConnection1)
da.FillSchema(ds, SchemaType.Source, "cilent")
da.Fill(ds, "client")
SqlConnection1.Close()
bind.DataSource = ds
bind.DataMember = "client"
Me.TextBox1.DataBindings.Add(New Binding("text", bind, "id", True))
Me.nametext.DataBindings.Add(New Binding("text", bind, "tech_name", True))
Me.ComboBox1.DataBindings.Add(New Binding("text", bind, "tech_sec", True))
Me.ComboBox2.DataBindings.Add(New Binding("text", bind, "tech_level", True))
Me.usertext.DataBindings.Add(New Binding("text", bind, "tech_user_name", True))
Me.passtext.DataBindings.Add(New Binding("text", bind, "tech_password", True))
Me.pass1text.DataBindings.Add(New Binding("text", bind, "tech_rpassword", True))
Me.ComboBox3.DataBindings.Add(New Binding("text", bind, "user_type", True))
Label13.Text = username
End Sub
its binding succsefully but what i want is to only binding the data that comes from my search
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|