Click here to Skip to main content
12,691,231 members (32,850 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB 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
            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
                XtraMessageBox.Show(" Please Fill The Following Fields : " & vbCrLf & "--------------------------------------" & vbCrLf & sFields, "Field Validator", MessageBoxButtons.OK)
            End If

        Catch ex As Exception
        End Try
    End Sub

Private Sub IsValidData()
            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
        End Try
    End Sub

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

1 solution

Rate this: bad
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.
OriginalGriff 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 5 Jan 2013
Copyright © CodeProject, 1999-2017
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