vb.net选中内容,vb组合框选中的代码
vb.net中combobox选中的内容怎么存到数据库?不用dataset和adapter。用的是
不管怎么样,都肯定要用到oledbCommand对吧。因为只有他能向数据库传达命令。
成都创新互联公司专业提供成都主机托管四川主机托管成都服务器托管四川服务器托管,支持按月付款!我们的承诺:贵族品质、平民价格,机房位于中国电信/网通/移动机房,双线服务器托管服务有保障!
在程序中向oledbCommand下达命令有三种方式,其中两个就是你说的dataset和adapter;还有一种就是:ExecuteReader;
给你一个我用的例子:
dim conContent as new system.data.oledb.oledbconnection("provider=Microsoft.jet.oledb.4.0;data source=bbs.mdb;")
conContent.open
using comContent as new system.data.oledb.oledbcommand("SELECT * FROM contenttitle WHERE 编号='" strNumber "'",conContent)
with comContent.ExecuteReader
if .hasrows then
.read
' 这里是一大段的操作
end if
end with
end using
这段程序,连接了一个数据库,然后从数据库中取出数据,然后进行操作,这段程序完了之后,comContent这个oledbCommand变量就消失了,从而不会影响再次对数据库连接(conContent)的操作。
如果你需要写数据,那直接把SQL语句改成update就好了。
vb.net textbox1选中的文本,拖放到textbox2?
很久没有上这里了,今天看到了这个问题,尝试做了一个;
本例以源文本框TextBox1全部文字作为拖放文字为例,实现拖放
1、向一个窗体中添加两个文本框,分别名为TextBox1,TextBox2。注意:把TextBox2控件的AllowDrop属性设置成True,这点不要遗漏。
2、完整的代码如下:
Public Class Form1
Private MouseIsDown As Boolean = False
Private Sub TextBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseDown
'设置一个标志以显示鼠标已按下。
MouseIsDown = True
End Sub
Private Sub TextBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseMove
If MouseIsDown Then
'开始拖动(将TextBox1的文本内容作为拖放内容)。
TextBox1.DoDragDrop(TextBox1.Text, DragDropEffects.Copy)
End If
MouseIsDown = False
End Sub
Private Sub TextBox2_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragEnter
'检查正在被拖放的数据的格式。
If (e.Data.GetDataPresent(DataFormats.Text)) Then
'显示复制光标(表示是拖放行为)。
e.Effect = DragDropEffects.Copy
Else
'显示不放置光标(表示不是拖放行为)。
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub TextBox2_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles TextBox2.DragDrop
'粘贴文本(将拖放内容作为TextBox2的文本内容)。
TextBox2.Text = e.Data.GetData(DataFormats.Text)
End Sub
End Class
VB.NET如何获得当前划选内容?
Private Declare Function GetAsyncKeyState Lib "user32" Alias "GetKeyState" (ByVal vKey As Long) As Integer
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Const VK_CONTROL = H11
Private Const SWP_NOMOVE = H2
Private Const SWP_NOSIZE = H1
Private Const HWND_TOPMOST = -1
Private Const KEYEVENTF_KEYUP = H2
Private Const WM_PASTE = H302
Private Sub Form_Load()
SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
Timer1.Interval = 100
Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyControl) And H7FFF Then
On Error Resume Next
keybd_event vbKeyControl, 0, 0, 0
keybd_event vbKeyC, 0, 0, 0
keybd_event vbKeyC, 0, KEYEVENTF_KEYUP, 0
keybd_event vbKeyControl, 0, KEYEVENTF_KEYUP, 0
Text1.Text = ""
SendMessage Text1.hwnd, WM_PASTE, 0, 0
End If
End Sub
VB.NET中怎样用API获得文本框中的选中文本
Public Declare Auto Function GetWindowText Lib "user32" Alias "GetWindowText" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Public Declare Auto Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLength" (ByVal hwnd As Integer) As Integer
Public Function GetText(ByVal hwnd As Integer) As String
Dim nLen As Integer
nLen = GetWindowTextLength(hwnd)
GetText = Space(nLen)
GetWindowText(hwnd, GetText, nLen)
End Function
VS2008测试通过, 函数GetText传入的就是对应文本框的句柄.
如何实现VB.NET实现代码在datagridview选中行,并在datagridview显示区域居中
非常简单
一:如果知道要选中的行号
datagridview1.Rows(行号).Selected
=
True
datagridview1.FirstDisplayedScrollingRowIndex
=
行号
第一行是选中行号所在的行,第二行是移动滚动条将选中的行在显示区域的最上放显示出来。
二:根据内容选中行并显示
For
i
=
To
datagridview1.Rows.Count
-
1
If
datagridview1.Rows(i).Cells("列的名称").Value
=
要选中行列的值
Then
datagridview1.Rows(i).Selected
=
True
datagridview1.FirstDisplayedScrollingRowIndex
=
i
End
If
Next
而且,如果你不想选中的行显示到最上面,可以这样:
For
i
=
To
datagridview1.Rows.Count
-
1
If
datagridview1.Rows(i).Cells("列的名称").Value
=
要选中行列的值
Then
datagridview1.Rows(i).Selected
=
True
Dim
indeI
As
Integer
=
i
-
15
If
indeI
1
Then
indeI
=
1
datagridview1.FirstDisplayedScrollingRowIndex
=
indeI
End
If
Next
上面的代码是根据某列的值选中行,并且移动滚动条将选中的行在显示区域的第15行显示。
VB.net怎么在RichTextBox寻找字符串,找到后并选中找到的字符串?
请参考下面的代码,希望能帮到你。
假设在richtextbox1中查找字符串"你是谁":
Dim start As Integer = richtextbox1.Find("你是谁", 0, RichTextBoxFinds.MatchCase)
if (start = 0) {
richtextbox1.SelectionStart = start
richtextbox1.SelectionLength = "你是谁".Length
}
网站栏目:vb.net选中内容,vb组合框选中的代码
本文URL:http://azwzsj.com/article/dscpgoe.html