Click here to Skip to main content
15,880,956 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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

1 solution

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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900