Home > front end >  Return data from a DevExpress XtraDialog
Return data from a DevExpress XtraDialog

Time:07-15

I'm using Visual Basic and DevExpress WinForm and I made a simple example below to show my problem. In the code is a Form with SimpleButton. Clicking the button shows XtraDialog with User Control. The User Control has a TextBox.

What I wish to do, is to get the input of this TextBox out of the User Control, into the Form, and not using a Module or SQL-Table, but like a DevExpress Input Box, through the Ok button.

Place use the example below, I'm very new to DevExpress and up to now still had any success implementing DevExpress into my code

Imports DevExpress.XtraEditors
Imports DevExpress.XtraLayout
Imports System
Imports System.Windows.Forms

Public Class XtraDialog1
Inherits Form

Public Sub New()
    InitializeComponent()
    AddHandler Me.SimpleButton1.Click, AddressOf simpleButton1_Click
End Sub

' Button Action
Private Sub simpleButton1_Click(ByVal sender As Object, ByVal e As EventArgs)

    ' Declare User Control
    Dim myControl As New ucExample()

  ' Show Popup
    If DevExpress.XtraEditors.XtraDialog.Show(myControl, "Title", MessageBoxButtons.OKCancel) = DialogResult.OK Then
        ' do something
    End If
End Sub
End Class

UserControl

Public Class ucExample

Dim result As String
Public Sub New()
    result = TextEdit1.Text
End Sub
End Class

CodePudding user response:

I'm a bit rusty on my DX stuff, but pretty sure all you need to do is change the access modifier and make result public. Would recommend reading up on Access Modifiers because the idea is that you should keep it as restrictive as possible. https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/language-features/declared-elements/access-levels.

I would use a readonly property for this, you might want to play around a little as to where it goes in the stack (ie In the user control, or the XtraDialog). There is also a Modifier property for components in the Form and UserControl designers you may want to familiarise yourself with.

Changing the UC to this:

Public Class ucExample
    Public ReadOnly Property result As String
        Get
            Return TextEdit1.Text
        End Get
    End Property
    Public Sub New()
        result = TextEdit1.Text
    End Sub
End Class

Then I also thing you want to change the usage of your Dialog a little to get the result.

Dim dlg As New DevExpress.XtraEditors.XtraDialog()
If dlg.Show(myControl, "Title", MessageBoxButtons.OKCancel) = DialogResult.OK Then
    Dim result As String = dlg.result
End If

Unable to test this myself right now, as don't have access to DX right now but hope this should be enough to get you heading in the right direction

CodePudding user response:

After some research and help from DevExpressUserSupport, here is a working version

Form

Public Class XtraDialog2

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim myControl As New ucExample()
    If DevExpress.XtraEditors.XtraDialog.Show(myControl, "Title", MessageBoxButtons.OKCancel) = DialogResult.OK Then
        Dim result As String = myControl.result
        MsgBox(result)
    End If

End Sub

End Class

User Control

Public Class ucExample
Public ReadOnly Property result As String
    Get
        Return TextEdit1.Text
    End Get
End Property

End Class

  • Related