Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
HI All,
 
I have one form consisting of 32 fields in which most of them are mandatory.After
clicking on save button i am adding the field's related name to Collections(List of string) and displaying message box with the names.I want the focus to move to the first control displaying in message box.
 
I am doing something like this
 
In button Click
 
 Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            IsValidData()
            If m_InvalidList.Count > 0 Then
                Dim sFields As String = ""
                For iCnt As Int32 = 0 To m_InvalidList.Count - 1
                    sFields &= m_InvalidList(iCnt).ToString & vbCrLf
                Next
                XtraMessageBox.Show(" Please Fill The Following Fields : " & vbCrLf & "--------------------------------------" & vbCrLf & sFields, "Field Validator", MessageBoxButtons.OK)
            Else
                SaveGenLedgerMaster()
            End If
 
        Catch ex As Exception
            ErrorLog(ex)
        End Try
    End Sub
 

 
  Private Sub IsValidData()
        Try
            m_InvalidList.Clear()
            If xtbGLName.Text = "" Then m_InvalidList.Add("General Ledger Name")
            If cmbGLSchedule.Text = "" Then m_InvalidList.Add("Schedule name")
            If ccbCompany.Text = "" Then m_InvalidList.Add("Company")
            If ccbSegment.Text = "" Then m_InvalidList.Add("Segment")
 
        Catch ex As Exception
            ErrorLog(ex)
        End Try
    End Sub
 

I want to focus the control binded to the first string in the List .How can i do this..is there any way other than this..like adding control to the list instead and set focus...please help me out..
Posted 4-Jan-13 20:50pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The way I would do it is to change the storage and reporting slightly.
Instead of storing the Text property, and handing a string through to your XtraMessageBox, I would make the m_InvalidList a list of Control rather than string. I would add the invalid controls to the list and hand them through complete to let the message box decide how best to report them. Setting the focus then just becomes a case of using the Focus method of the first control in the m_Invalidlist.
  Permalink  
Comments
OriginalGriff at 5-Jan-13 4:55am
   
Do you want to try asking that again?
Because I do not understand from that what you are trying to do.
OriginalGriff at 5-Jan-13 5:28am
   
You do realise that all controls have a Text property? And that for a ComboBox the Text is the selected value as displayed?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 450
1 OriginalGriff 403
2 Sergey Alexandrovich Kryukov 195
3 CPallini 189
4 CHill60 180
0 OriginalGriff 6,092
1 Sergey Alexandrovich Kryukov 4,958
2 Maciej Los 3,269
3 Peter Leow 3,129
4 DamithSL 2,490


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 5 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100