how i bind bindingsource control

sajeel

Member
Joined
Jul 9, 2008
Messages
17
Programming Experience
Beginner
hi
i am giving bindingsource control like this
bind1.DataSource = dsAppNames ' dataset name

this dataset was made using a xml file


and i want to bind this bind1 bindingsource control to my form contrl

like textboxes
 
Firstly, let me suggest that update your profile because you've got your Framework version as 1.1 which is obviously wrong if you're using a BindingSource.

Secondly, a BindingSource is not a control. It's a component.

As to your question, you bind a BindingSource to a control the same way you bind any other list. For complex data binding, like with a grid or list control, you assign it to the DataSource property. For simple data binding you use the DataBindings property, e.g.
VB.NET:
myTextBox.DataBindings.Add("Text", myBindingSource, "ColumnName")
Read the documentation for the Control.DataBindings property.
 
bindingsource

VB.NET:
Dim streamRead As New System.IO.FileStream("..\..\services.xml", _
               System.IO.FileMode.Open)

        dsAppNames.ReadXml(streamRead) 'Dataset can read content from FileStream.

        bind1.DataSource = dsAppNames

        'bndSource.DataMember = dsAppNames.Tables(0).TableName

        txtDelaytime.DataBindings.Add("Text", bind1, "name")

this is my code

when i am binding the bindingsource contrl to textbox
i am getting this error
Cannot bind to the property or column name on the DataSource.
Parameter name: dataMember
 
Binding source control

i have a form and
bind2 is my bindingsource control

VB.NET:
Private Sub gridviewBind_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridviewBind.DoubleClick

        Try
            currentId = gridviewBind.CurrentRow.Index ' store the selected  Datagrid row Id

        Catch

        End Try
        bind2.DataSource = dsLoad
        bind2.Filter = currentId
        gridviewBind.DataSource = bind2

    End Sub

when i slected paritcular row in datagridview i want to display records of that row in my form controls like textboxes..
 
You can't just bind something to a DataSet and expect it to work. A DataSet doesn't contain any data. A DataSet contains DataTables. It's the tables that contain the data. If you assign a DataSet to the BindingSource's DataSource then you must assign the name of the DataTable containing the data to the DataMember property. Otherwise you need to assign the DataTable itself to the DataSource.

As for the question of master/detail data-binding, read this.
 
bindingsource control

hi
how i use binding source contrl with dataset
to add, delte,update a record . if my datasourse is xml file

VB.NET:
bind2.DataSource =dataset

i am binding my datasource bind2 with a  dataset .

and binding to  form controls(textboxes) like

Me.txtDelaytime.DataBindings.Clear()
        Me.txtDelaytime.DataBindings.Add("Text", bind2, "DelayTime")
  Me.txtLastExecTime.DataBindings.Clear()

and i am adding new rows 
Dim dr As DataRow ' Add New Datarow
            dr = dtSaveXml.NewRow  ' Create New Row in dtSaveXml datatable
            dr("ApplicationSource") = cmb_AppSource.Text
            dr("ApplicationDestination") = cmbapp_distination.Text

dtSaveXml.Rows.Add(dr) 
dataset.Tables.Add(dtSaveXml)
dataset.WriteXml(str)

when i change the textboxes value how i generate new records into xml file
 
bindingsource add ,edit delete

VB.NET:
dtSaveXml = dsLoad.Tables(0)' datatable loaded from dataset
 bind2.DataSource = dtSaveXml  'bind2 is datasource control
next how i do add new records , update , delete back to datatable
 
datasource

how i use datasource t add new record , and update delete

when i bounding datasource like

dtSaveXml = dsLoad.Tables(0)
bind2.DataSource = dtSaveXml ' bind the datatable to BindingSource


dgridviewBind.DataSource = bind2 ' i am binding boundingsource to datagrid

after displying records in datagrid .. when i click on datagrid i am displying records data into textboxes

when i want to add new records or change records ..

how can i do
 
If you want to add a new record you can call AddNew on the BindingSource. Presumably editing will be done through the UI. To delete you get the current DataRowView from the BindingSource's Current property and call its Delete method.
 
I'm not against providing code but I am against providing code when people haven't looked for themselves first. You know that you need to use the AddNew method and Current property of the BindingSource. Have you read the Help documentation for those members? They may not give you everything you need. They may not even help you at all, but I, for one, would expect that people would at least try first. You learn by doing, so do. It will benefit you in the end. If you try and can't get it, then ask. I'll be the first one to provide assistance in that case.
 
If you want to add a new record you can call AddNew on the BindingSource. Presumably editing will be done through the UI. To delete you get the current DataRowView from the BindingSource's Current property and call its Delete method.

If this thread isn't dead yet, I'd also like some clarification on this point. I'm binding against an object as well and I'm having trouble understanding the bindingSource.AddNew function.

I have a class called Person, which has properties of FirstName, LastName, and Description. It also has an Id, which I'm attempting to make unique with its New constructor.

On my Manage People form I have fields for each of these properties except Id, and a listbox to display all the people.

In the code-behind for the form, I have a list to hold Person objects.
VB.NET:
Private peopleList as List(Of Person) = New List(Of Person)

Next, I created an object datasource for this class. Then I created a BindingSource called bs_Person, and set its DataSource to the Person object.

Here's where I get lost.

1. I don't know if I should set the DataSource of bs_Person to personList, or to the Person object.
2. I don't understand exactly what the AddNew method of the bindingsource does.
3. There are several other methods like "CancelEdit", "EndEdit", etc. that would suggest I should be invoking some state of editability on something; they also seem to imply the existence of other methods like "BeginEdit", which I'm not seeing.

All in all, I'm utterly at a loss as to how to proceed. A clear example would be very helpful.
 
Back
Top