vb.net怎么使用表格控件?
DataGridView控件,放一个DataGridView1和Button1到窗体,下面是按钮下代码
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.DataGridView1.AllowUserToAddRows = False
DataGridView1.RowTemplate.Height = 200
DataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.None
For i = 1 To 3
Me.DataGridView1.Columns.Add("列" i.ToString, "列" i.ToString)
Me.DataGridView1.Rows.Add()
Next
Me.DataGridView1.Columns(0).Width = 100
Me.DataGridView1.Columns(1).Width = 500
Me.DataGridView1.Columns(0).Width = 300
End Sub
'自己设置相关需要的属性即可
VB下如何使用iPlotLibrary控件
VB.NET的iPlotLibrary控件是VB.NET最常用也最简单的一种控件。下面介绍一下如何使用iPlotLibrary控件。
新建一个VB.NET新程序
左侧工具箱选择‘iPlotLibrary’控件
中间桌布上拖动,放在中间
iPlotLibrary控件最常用的两个属性:name。一般使用简写的Btn来代表iPlotLibrary按钮,IT业内的规定。
另一个常用的属性,Text。用来显示我们当前的按钮文字,默认是iPlotLibrary1。
双击iPlotLibrary控件属性,自动进入click事件。click事件的意思是只要单击iPlotLibrary控件,就会触发事件,这个事件就是代码中所写的要弹出的对话框hello world!
使用按键F5,调试运行。结果如下,这样便是成功了。
求VB.net datagrid 控件的使用方法(入门级)
Dim tab1 As String
Dim DS As New DataSet
Dim SqlStr As String
Dim DTS_A As New DataGridTableStyle
Dim Col_A1, Col_A2, Col_A3 As New DataGridTextBoxColumn
Dim Col_bo As New DataGridBoolColumn
'DS.Tables("tab1").Columns.Add("check", System.Type.GetType("System.Boolean"))
'DS.Tables("tab1").Columns("check").DefaultValue = False
Dim Col_A() As DataGridColumnStyle = {Col_bo, Col_A1, Col_A2, Col_A3}
'主窗口
Private Sub fICitem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ProgressBar1.Hide()
grdStyles("tab1")
SQLConn(conn)
Dim i As Integer
'Dim arr As New ArrayList
SqlStr = "SELECT ID, diqu, dname FROM a_diqu Order by ID"
If Not SQLFill(conn, DA, DS, SqlStr, "diqu") Then
MsgBox("服务器连接失败")
Else
Dim dr As DataRow
For Each dr In DS.Tables("diqu").Rows
'arr.Add(dr("diqu") "." dr("dname"))
cmbDiqu.Items.Add(dr("diqu") "." dr("dname"))
Next
End If
'cmbDiqu.DataSource = arr
cmbDiqu.SelectedIndex = -1
cmbDiqu.Text = ""
End Sub
'DataGrid格式
Private Sub grdStyles(ByVal tab As String)
Dim ii1 As Integer
Dim DTS_A1() As String = {"check", "fshortnumber", "fnumber", "fplanprice"}
Dim DTS_A2() As String = {"检查框", "货号", "上市月份", "单价"}
Dim DTS_A3() As Integer = {50, 120, 120, 120} '长度
Dim DTS_A4() As Integer = {2, 0, 2, 1} '对齐方式
DTS_A.MappingName = tab
DTS_A.GridColumnStyles.Clear()
DTS_A.AllowSorting = True
DTS_A.ReadOnly = True
DTS_A.BackColor = Color.DarkGray
DTS_A.AlternatingBackColor = Color.LightGray
For ii1 = 0 To DTS_A1.Length - 1
Col_A(ii1).MappingName = DTS_A1(ii1)
Col_A(ii1).HeaderText = DTS_A2(ii1)
Col_A(ii1).Width = DTS_A3(ii1)
Col_A(ii1).NullText = ""
Col_A(ii1).Alignment = DTS_A4(ii1)
Next
DTS_A.GridColumnStyles.AddRange(Col_A)
grdItem.TableStyles.Add(DTS_A)
grdItem.ReadOnly = True
End Sub
Private Sub fICitem_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
SQLClose(conn)
End Sub
'显示表单
Private Sub Show1()
grdStyles("tab1")
txtNum.Text = Trim(txtNum.Text)
grdItem.DataSource = Nothing
SQLStr = "select * from t_icitem_new"
SQLStr = " where fshortnumber like '" txtNum.Text "%'"
SQLStr = " order by fshortnumber"
SQLFill(conn, DA, DS, SQLStr, tab1)
grdItem.CaptionText = "货号资料"
grdItem.DataSource = DS.Tables(tab1)
ShowRow()
End Sub
'数据同步显示
Private Sub ShowRow()
Dim dr As DataRow
If DS.Tables(tab1).Rows.Count 0 Then
If grdItem.CurrentRowIndex DS.Tables(tab1).Rows.Count Then
grdItem.CaptionText = grdItem.CurrentRowIndex + 1 "/" DS.Tables(tab1).Rows.Count
dr = DS.Tables(tab1).Rows(grdItem.CurrentRowIndex)
txtNum.Text = dr.Item("fshortnumber")
txtPrice.Text = dr.Item("fplanprice")
cmbMonth.Text = dr.Item("fnumber")
Else
txtNum.Text = ""
txtPrice.Text = ""
cmbMonth.Text = ""
End If
Else
txtNum.Text = ""
txtPrice.Text = ""
cmbMonth.Text = ""
End If
End Sub
Private Sub grdItem_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdItem.CurrentCellChanged
ShowRow()
End Sub
'鼠标选定行
Private Sub grdItem_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdItem.CurrentCellChanged
ShowRow()
End Sub
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnSelect.Click, btnUpdate.Click, btnInsert.Click, btnDelete.Click
Select Case sender.name
Case "btnSelect" '查询
Show1()
Case "btnUpdate" '修改
SUpdate()
Case "btnInsert" '新增
SInsert()
Case "btnDelete" '删除
SDelete()
End Select
End Sub
'修改
Private Sub SUpdate()
txtNum.Text = Trim(txtNum.Text)
txtPrice.Text = Trim(txtPrice.Text)
If MsgBox("确定更新?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
SQLStr = "UPDATE t_icitem_new SET "
SQLStr = "fnumber='" cmbMonth.SelectedItem "', "
SQLStr = "fplanprice='" txtPrice.Text "' "
SQLStr = "WHERE fshortnumber='" txtNum.Text "'"
If Not SQLFill2(conn, SQLStr) Then
MsgBox("抱歉,更新失败:(")
End If
Show1()
End If
End Sub
'新增
Private Sub SInsert()
txtNum.Text = Trim(txtNum.Text)
txtPrice.Text = Trim(txtPrice.Text)
If MsgBox("确定新增?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
SQLStr = "SELECT fshortnumber "
SQLStr = "FROM t_icitem_new "
SQLStr = "WHERE fshortnumber = '" txtNum.Text "' "
SQLFill(conn, DA, DS, SQLStr, "Tmp")
If DS.Tables("Tmp").Rows.Count = 0 Then '如果没有资料则新增
SQLStr = "INSERT INTO t_icitem_new (fshortnumber,fnumber,fplanprice) VALUES("
SQLStr = "'" txtNum.Text "', "
SQLStr = "'" cmbMonth.SelectedItem "', "
SQLStr = "'" txtPrice.Text "')"
If Not SQLFill2(conn, SQLStr) Then
MsgBox("抱歉,新增失败:(")
End If
Show1()
Else
MsgBox("资料已存在")
End If
End If
End Sub
'删除
Private Sub SDelete()
txtNum.Text = Trim(txtNum.Text)
txtPrice.Text = Trim(txtPrice.Text)
If MsgBox("确定删除" txtNum.Text "?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2) = MsgBoxResult.Yes Then
SQLStr = "DELETE FROM t_icitem_new "
SQLStr = "WHERE fshortnumber='" txtNum.Text "'"
If Not SQLFill2(conn, SQLStr) Then
MsgBox("抱歉,删除失败:(")
End If
Show1()
End If
'键盘顺序
Private Sub txt_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) _
Handles txtFshop.KeyDown, txtItem.KeyDown
Select Case e.KeyCode
Case Keys.Return
SendKeys.Send("{TAB}")
Case Keys.Right
SendKeys.Send("{TAB}")
Case Keys.Left
SendKeys.Send("+{TAB}")
Case Keys.Down
SendKeys.Send("{TAB 10}")
Case Keys.Up
SendKeys.Send("+{TAB 10}")
End Select
End Sub
vb.net自定义控件问题
首先,你已经完成的步骤是:
1.新建一个用户控件[注意,用户控件(UserControl)不是自定义控件(CustomControl)]
2.给用户控件起个名字(我在此处起名叫 RadioList)
3.在用户控件上画一个 GroupBox,命名为 RadioGroup,
并将其 Dock 属性设置为 Fill
然后,你需要做的是动态增减控件。
如果你以前用过 VB 6,你可能会想到控件数组,
但在此处,你可以直接增删控件。
具体实现如下:
4.在 GroupBox 里画一个 FlowLayoutPanel,命名为 RadioPanel,
将其 AutoScroll 属性设置为 True,即自动显示滚动条,
并设置其 FlowDirection 属性(例如设置为 TopDown)
这样就省去了手动调整 RadioButton 位置的麻烦
5.实现选项的动态增减(以下只是我的思路,你可以发挥一下)
(十分简洁,注释除外):
''' summary
''' 创建一个新的 RadioButton。
''' /summary
Private Function CreateRadio() As RadioButton
Dim NewRadio As New RadioButton
components.Add(NewRadio)
'components 字段由控件设计器自动创建,
'此代码目的是使控件在销毁(Dispose)时能自动销毁 RadioButton
'详情参见 RadioList.Designer.vb
NewRadio.Parent = RadioPanel
'设置容器
AddHandler NewRadio.CheckedChanged, AddressOf RadioButtons_CheckedChanged
'设置事件处理程序
Return NewRadio
End Function
''' summary
''' 移除已存在的 RadioButton。
''' /summary
Private Sub RemoveRadio(ByVal dest As RadioButton)
components.Remove(dest)
dest.Dispose()
End Sub
'无中生有的 RadioButton 的事件处理程序
Private Sub RadioButtons_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
'在此处设置选中项的属性,通过 sender 来确定不同的 OptionButton
'你可以通过将 OptionButton 放在一个列表,
'如 List(Of OptionButton) 中来像数组一样维护选项的次序
'注意,此处需要判断 sender 的 Checked 属性是否为 True
'因为 Changed 是“改变”,而不是“选中”
'例如:
If DirectCast(sender, RadioButton).Checked Then
SelectedIndex = ...
End If
End Sub