Click here to Skip to main content
15,886,110 members

How to move the focus to a particular field

DileepkumarReddy asked:

Open original thread
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..
Tags: Visual Basic

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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