2016-07-13 5 views
0

데이터베이스 테이블의 데이터를 표시하는 UltraWinGrid가 포함 된 .NET 프로젝트가 있습니다. UWG의 양식에는 3 개의 버튼이 있습니다. '새 데이터', '데이터 편집'및 '데이터 삭제'가 있습니다. 처음 두 개는 저장할 데이터를 입력/편집 할 수있는 컨트롤이있는 새로운 양식을 엽니 다. 저장 기능은 정상적으로 작동하지만 초기 양식 (UWG 사용)을보기 위해 양식을 닫을 때 데이터가 새로 고쳐지지 않고 닫고 다시 열 때만 그렇게됩니다.별도의 폼에서 UltraWinGrid 새로 고침

그래서 새 양식에서 저장 버튼을 누르면 UWG를 새로 고칠 수있는 방법이 있습니까? (난 이미 UWG로드 다시 함수를 호출 시도,하지만 난 그것을 공유 방법을 만들 수 없기 때문에이 때문에 연결에 작동하지 않습니다)

저장 기능 코드 :

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click 

    Dim m_cn As New OleDbConnection 
    m_cn = m_database.getConnection() 


    If txtFirstName.Text = "" Then 
     MsgBox("First name cannot be blank") 

    ElseIf txtLastName.Text = "" Then 
     MsgBox("Last name cannot be blank") 

    ElseIf txtAge.Text = "" Then 
     MsgBox("Age cannot be blank") 

    ElseIf txtPostCode.Text = "" Then 
     MsgBox("Postcode cannot be blank") 

    Else 
     Dim personID As Integer = database.SaveNewPerson(txtFirstName.Text, txtLastName.Text, txtAge.Text, txtPostCode.Text, m_cn) 

     MsgBox("Save successful") 

     txtFirstName.Text = "" 
     txtLastName.Text = "" 
     txtAge.Text = "" 
     txtPostCode.Text = "" 

    End If 

End Sub 

코드가 UWG는로드 :

Public Sub getPeople() 

    Try 
     Dim sql As String = "SELECT * FROM tblPerson" 
     Dim cm As New OleDbCommand(sql, m_database.getConnection()) 
     Dim da As New OleDbDataAdapter(cm) 
     Dim dt As New DataTable() 
     da.Fill(dt) 
     ugData.DataSource = dt 

    Catch Ex As Exception 
     MsgBox("Could not load people") 
    End Try 

End Sub 

답변

2

당신은하지 절약 형태로 호출하는 형태로 getPeople 함수를 호출해야합니다.
저장 양식이 올바르게 종료되었는지 그리고이 정보가 ShowDialog에 대한 호출의 반환 값으로 사용 가능한지 알아야합니다. 개인 데이터를 저장 귀하의 버튼을 OK로 DialogResult 속성 집합이 있어야하고 모든가 잘 어울리는 경우,이 코드는

' Open the form that inserts a new person 
' Change that name to your actual form class name... 
Using fp = new frmPerson() 

    ' If the user presses the button to save and everything goes well 
    ' we get the DialogResult property from the button pressed 
    if fp.ShowDialog() = DialogResult.OK Then 

     ugData.DataSource = Nothing 
     getPeople() 

    End If 
End Using 

공지 사항의 포인트 을 작동합니다. 즉, 버튼 저장 절차에서 문제가 발생하면 양식 닫기를 닫아 DialogResult 속성을 없음으로 변경해야합니다.

Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click 

    Dim m_cn As New OleDbConnection 
    m_cn = m_database.getConnection() 


    If txtFirstName.Text = "" Then 

     MsgBox("First name cannot be blank") 
     Me.DialogResult = DialogResult.None 
    ElseIf txtLastName.Text = "" Then 
     MsgBox("Last name cannot be blank") 
     Me.DialogResult = DialogResult.None 
    ElseIf txtAge.Text = "" Then 
     MsgBox("Age cannot be blank") 
     Me.DialogResult = DialogResult.None 
    ElseIf txtPostCode.Text = "" Then 
     MsgBox("Postcode cannot be blank") 
     Me.DialogResult = DialogResult.None 
    Else 
     Dim personID As Integer = database.SaveNewPerson(txtFirstName.Text, txtLastName.Text, txtAge.Text, txtPostCode.Text, m_cn) 

     MsgBox("Save successful") 

     txtFirstName.Text = "" 
     txtLastName.Text = "" 
     txtAge.Text = "" 
     txtPostCode.Text = "" 
    End If 
End Sub 
+1

안녕하세요, 스티브, 답변을 주셔서 감사합니다, 어떻게 사용하지 않거나 이해하지 않기 때문에 vb.net에서이 코드가 바뀔까요? – David

+0

지금 수정되었습니다 ... – Steve

+1

러블리, 고마워요! – David