none
Auswahl speichern Kombinationsfelder in Form RRS feed

Antworten

  • Hallo,

    Du benötigst für jede Einstellung einen eigenen Eintrag, z. B.:

    Public Class SettingsForm1
        Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            ReadSettings()
        End Sub
    
        Private Sub Form_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) _
            Handles MyBase.FormClosing
            WriteSettings()
        End Sub
    
        Private Sub ReadSettings()
            With My.Settings
                For Each itm As String In .Combo1_Items
                    ComboBox1.Items.Add(itm)
                    ComboBox2.Items.Add(itm)
                Next
                If .Combo1_UserSelection <> "" Then
                    ComboBox1.SelectedIndex = ComboBox1.Items.IndexOf(.Combo1_UserSelection)
                End If
    
                If .Combo2_UserSelection <> "" Then
                    ComboBox2.SelectedIndex = ComboBox1.Items.IndexOf(.Combo2_UserSelection)
                End If
            End With
        End Sub
    
        Private Sub WriteSettings()
            With My.Settings
                .Combo1_Items.Clear()
                For Each itm As String In Me.ComboBox1.Items
                    .Combo1_Items.Add(itm)
                Next
    
                If ComboBox1.SelectedIndex >= 0 Then
                    .Combo1_UserSelection = CStr(ComboBox1.SelectedItem)
                Else
                    .Combo1_UserSelection = ""
                End If
    
                If ComboBox2.SelectedIndex >= 0 Then
                    .Combo2_UserSelection = CStr(ComboBox2.SelectedItem)
                Else
                    .Combo2_UserSelection = ""
                End If
                .Save()
            End With
        End Sub
    End Class

    Gruss Elmar

    P. S.: Es gibt auch ein spanisches VB.NET Forum

    Dienstag, 21. Mai 2013 08:03
    Beantworter

Alle Antworten

  • Hi Vitor,
    Zustände eines Programmes kann man in den Einstellungen (Settings) zwischen Programmende und Neustart für jeden Nutzer speichern. Für Deinen Fall wäre die Ablage einer Identifikation (ID) für die ausgewählten (selektierten) Einträge sinnvoll. Um zu entscheiden, welches die beste Variante ist, ist zuerst festzulegen, wie die Listen der Datenobjekte aussehen, die in den Kombinationsboxen angezeigt werden. Wenn jedes Datenobjekt aus ID und Anzeigetext besteht, dann merke Dir in den Einstellungen die ID’s der ausgewählten Einträge und lade sie bei Programmstart neu.
     
    --
    Peter Fleischer
    Dienstag, 14. Mai 2013 05:24
  • Freund Peter,

    Habe ich kann Beispielcode?

    Gruß
    Montag, 20. Mai 2013 21:35
  • Hallo Vitor,

    schau Dir mal an: My.Settings Object

    Dort findest Du Beispiele (Tasks) zum Laden und Speichern von Benutzereinstellungen.

    Gruß Elmar

    Montag, 20. Mai 2013 21:40
    Beantworter
  • Elmar Freund,

    Mit einem Stück Code, die zeigen, wenn ich das Programm starten die beiden Combobox mit dem gleichen Namen gibt, obwohl ich andere Namen wählen.

    Was ich will, ist, den Code zu ändern, um zu ermöglichen und zu erfassen verschiedenen Namen in verschiedenen Combobox.

    Wie lautet der Code?

    Hug

     Private Sub ReadSettings()
    
            With My.Settings
                For Each itm As String In .Combo1_Items
                    ComboBox1.Items.Add(itm)
                    ComboBox2.Items.Add(itm)
                Next
                If .Combo1_UserSelection <> "" Then
    
                End If
                ComboBox1.Text = .Combo1_UserSelection
                ComboBox1.Enabled = True
    
                If .Combo1_UserSelection <> "" Then
                    ComboBox2.Text = .Combo1_UserSelection
    
                    ComboBox2.Enabled = True
    
    
                End If
            End With
        End Sub
    
        Private Sub WriteSettings()
    
            With My.Settings
                .Combo1_Items.Clear()
               For Each itm As String In ComboBox1.Items
                    .Combo1_Items.Add(itm)
    
                Next
                If ComboBox1.SelectedIndex > -1 Then
                    Dim userSelection As String = ComboBox1.Items(ComboBox1.SelectedIndex).ToString
                    .Combo1_UserSelection = userSelection
                Else
                    .Combo1_UserSelection = ""
                End If
                .Save()
            End With
        End Sub

    Montag, 20. Mai 2013 22:18
  • Hallo,

    Du benötigst für jede Einstellung einen eigenen Eintrag, z. B.:

    Public Class SettingsForm1
        Private Sub Form_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            ReadSettings()
        End Sub
    
        Private Sub Form_FormClosing(sender As System.Object, e As System.Windows.Forms.FormClosingEventArgs) _
            Handles MyBase.FormClosing
            WriteSettings()
        End Sub
    
        Private Sub ReadSettings()
            With My.Settings
                For Each itm As String In .Combo1_Items
                    ComboBox1.Items.Add(itm)
                    ComboBox2.Items.Add(itm)
                Next
                If .Combo1_UserSelection <> "" Then
                    ComboBox1.SelectedIndex = ComboBox1.Items.IndexOf(.Combo1_UserSelection)
                End If
    
                If .Combo2_UserSelection <> "" Then
                    ComboBox2.SelectedIndex = ComboBox1.Items.IndexOf(.Combo2_UserSelection)
                End If
            End With
        End Sub
    
        Private Sub WriteSettings()
            With My.Settings
                .Combo1_Items.Clear()
                For Each itm As String In Me.ComboBox1.Items
                    .Combo1_Items.Add(itm)
                Next
    
                If ComboBox1.SelectedIndex >= 0 Then
                    .Combo1_UserSelection = CStr(ComboBox1.SelectedItem)
                Else
                    .Combo1_UserSelection = ""
                End If
    
                If ComboBox2.SelectedIndex >= 0 Then
                    .Combo2_UserSelection = CStr(ComboBox2.SelectedItem)
                Else
                    .Combo2_UserSelection = ""
                End If
                .Save()
            End With
        End Sub
    End Class

    Gruss Elmar

    P. S.: Es gibt auch ein spanisches VB.NET Forum

    Dienstag, 21. Mai 2013 08:03
    Beantworter
  • Elmar Freund,

    Sehr gut! Herzlichen Glückwunsch! War es richtig!

    Sehr dankbar, mein Freund!


    Big Hug.

    Vitor Patricio
    Dienstag, 21. Mai 2013 20:18