如何在运行时不单击texbox的情况下在TextBox中显示文本 [英] how to display text in a TextBox without clicking on the texbox at run time

查看:84
本文介绍了如何在运行时不单击texbox的情况下在TextBox中显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在数据网格中有一个文本框,当用户从组合框选择OID时,该文本框会显示OID描述.但是问题是我的文本框仅在单击文本框时才显示文本.当用户选择OID时,该文本框将显示文本而无需单击它.


Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
       If e.ColumnIndex = 1 Then
           Dim Row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
           Select Case Row.Cells(1).Value
               Case "1.3.6.1.2.1.1.1.0" : TextBox1.Text = "sysDescr"
               Case "1.3.6.1.2.1.1.2.0" : TextBox1.Text = "sysObjectID"
               Case "1.3.6.1.2.1.1.3.0" : TextBox1.Text = "sysUpTime"
               Case "1.3.6.1.2.1.1.4.0" : TextBox1.Text = "sysContact"
               Case "1.3.6.1.2.1.1.5.0" : TextBox1.Text = "sysName"
               Case "1.3.6.1.2.1.1.6.0" : TextBox1.Text = "sysLocation"
               Case "1.3.6.1.2.1.1.7.0" : TextBox1.Text = "sysServices"
           End Select

       End If

   End Sub

解决方案

CellValueChanged事件只有在单元格失去焦点并且值更改后才会触发.
您将不得不使用DataGrid的另一个事件.在编辑单元格时,DGV唯一会触发的事件是KeyDown,KeyPress和KeyUp事件.


将JavaScript函数与Dropdown的onclick(或onchange,不确定)事件并在函数中更新您的文本框.您将必须在ItemCreated(或在GridView的情况下为RowCreated)事件中编写代码.您可以在每行的下拉列表中动态添加onclick属性,并将Textbox的ClientId传递给Javascript函数.


<code></code>TextBox1.Refresh();


I have a textBox in a datagrid which shows the OID description when a user select a OID from a combobox..But the problem is that my textbox is showing the text only when I click on the textbox..is there any way that make the textbox show text without clicking on it as soon as the user selects an OID.


Private Sub DataGridView1_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
       If e.ColumnIndex = 1 Then
           Dim Row As DataGridViewRow = DataGridView1.Rows(e.RowIndex)
           Select Case Row.Cells(1).Value
               Case "1.3.6.1.2.1.1.1.0" : TextBox1.Text = "sysDescr"
               Case "1.3.6.1.2.1.1.2.0" : TextBox1.Text = "sysObjectID"
               Case "1.3.6.1.2.1.1.3.0" : TextBox1.Text = "sysUpTime"
               Case "1.3.6.1.2.1.1.4.0" : TextBox1.Text = "sysContact"
               Case "1.3.6.1.2.1.1.5.0" : TextBox1.Text = "sysName"
               Case "1.3.6.1.2.1.1.6.0" : TextBox1.Text = "sysLocation"
               Case "1.3.6.1.2.1.1.7.0" : TextBox1.Text = "sysServices"
           End Select

       End If

   End Sub

解决方案

The CellValueChanged event doesn''t fire until the cell loses focus, and only if the value has changed.

You''ll have to use a different event of the DataGrid. The only events that the DGV fires while a cell is being edited are the KeyDown, KeyPress, and KeyUp events.


Hook up a javascript function to the Dropdown''s onclick (or onchange, not sure) event and update your textbox in the function. You''ll have to write code in the ItemCreated (or RowCreated in case of GridView) event. You can dynamically add the onclick attribute to the Dropdown in each row and pass the Textbox''s ClientId to the Javascript function.


<code></code>TextBox1.Refresh();


这篇关于如何在运行时不单击texbox的情况下在TextBox中显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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