如何将焦点移动到特定字段 [英] How to move the focus to a particular field

查看:93
本文介绍了如何将焦点移动到特定字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

全部好,



我有一个由32个字段组成的表单,其中大部分都是强制性的。

点击保存按钮我将字段的相关名称添加到集合(字符串列表)并显示带有名称的消息框。我希望焦点移动到显示在消息框中的第一个控件。



我正在做这样的事情



按钮点击



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..

推荐答案

我要做的就是改变稍微存储和报告。

我将m_InvalidList设置为Control而不是string的列表,而不是存储Text属性,并将字符串传递给XtraMessageBox。我会将无效的控件添加到列表中并将它们传递给完成,让消息框决定如何最好地报告它们。设置焦点然后只是使用m_Invalidlist中第一个控件的Focus方法。
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.


这篇关于如何将焦点移动到特定字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆