Ciao a tutti,

sto cercando di programmare il bindingnavigator ma non ci sto riuscendo.
In particolare non riesco ad effettuare l'operazione di inserimento.


Ho un treeview di cui prendo il codice del nodo selezionato ed ho tre textbox.
Nel momento in cui premo il tasto insert del bindingnavigator mi va in errore
"Impossibile aggiungere un elemento a un elenco a sola lettura o di dimensione fissa."

Potreste aiutarmi nella fase di inserimento?

Grazie a tutti

Rick

Vi posto il codice:


Public Class Form1
Private _dt As DataSet
Private stringa1 As String
Private stringa2 As String
Private stringa3 As String
Private valore As Decimal
Private newnavigator As New BindingNavigator()
Private newbindingsource As New BindingSource()

Private Sub BindingSourceSample_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.Barra_di_Binding.BindingSource = Me.newbindingsource
Me.newnavigator.Dock = DockStyle.Top
Me.Controls.Add(Me.newnavigator)

Me.Barra_di_Binding.Enabled = True
Me.BindingNavigatorPositionItem.Width = 50

_dt = New DataSet

_dt.Tables.Add("domande")
_dt.Tables("domande").Columns.Add("DomandaCodice")
_dt.Tables("domande").Columns.Add("ris1")
_dt.Tables("domande").Columns.Add("èris2")
_dt.Tables("domande").Columns.Add("ris3")

_dt.Tables("domande").Rows.Add("Nodo0")
_dt.Tables("domande").Rows.Add("Nodo1")
_dt.Tables("domande").Rows.Add("Nodo2")
'_dt.MultiSelect = False

'Me.TextBox1.DataBindings.Add("text", _dt, "domande.ris1")
'Me.TextBox2.DataBindings.Add("text", _dt, "domande.ris2")
'Me.TextBox3.DataBindings.Add("text", _dt, "domande.ris3")

'_dt.Rows(0).Selected = True

End Sub

Private Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect

valore = TreeView1.SelectedNode.Index

End Sub

Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click

' Create a Flag instance and add it to the BindingSource
stringa1 = TextBox1.Text
stringa2 = TextBox2.Text
stringa3 = TextBox3.Text
Me.Barra_di_Binding.BindingSource.Add(New Flag(valore, stringa1, stringa2, stringa3))

Me.BindingSource1.Position = Me.BindingSource1.Count - 1

End Sub

Class Flag

Public Sub New(ByVal name As Decimal, ByVal stringa1 As String, ByVal stringa2 As String, ByVal stringa3 As String)
Me.flagName = name
Me.flagName1 = stringa1
Me.flagName2 = stringa2
Me.flagName3 = stringa3
End Sub 'New

Private _flagName As Decimal
Public Property flagName() As Decimal
Get
Return _flagName
End Get
Set(ByVal value As Decimal)
_flagName = value
End Set
End Property
Private _flagName1 As String
Public Property flagName1() As String
Get
Return _flagName1
End Get
Set(ByVal value As String)
_flagName1 = value
End Set
End Property
Private _flagName2 As String
Public Property flagName2() As String
Get
Return _flagName2
End Get
Set(ByVal value As String)
_flagName2 = value
End Set
End Property
Private _flagName3 As String
Public Property flagName3() As String
Get
Return _flagName3
End Get
Set(ByVal value As String)
_flagName3 = value
End Set
End Property


End Class 'Flag
End Class