您的位置:首页 > 编程语言 > VB

VB.Net学习笔记(三)

2015-12-25 09:46 435 查看
1、 ListBox绑定数据

Dim dt AsNew DataSet

        dt = DJGL.ReturnDT("select name from t_item where type='控件列表'")

        ListBox1.DataSource = dt.Tables(0)

        ListBox1.DisplayMember = "name"

        ListBox1.ValueMember = "name"

2、 Tag属性

Tag的类型是Object,因此可以保存任意的控件Control,调用比较方便。

3、 ListView绑定数据及多列显示

ListView1.Columns.Add(ch1)

        ListView1.Columns.Add(ch2)

        Dim RCount AsInteger = dt.Tables(0).Rows.Count

        Dim i AsInteger

        For i = 0 To RCount - 1

            ListView1.Items.Add(dt.Tables(0).Rows(i)(0).ToString()) 加第一列

            ListView1.Items(i).SubItems.Add("NULL") 加第二列

        Next

4、 ListBox中右键菜单并选择

在MouseDown事件中:

        If e.Button = Windows.Forms.MouseButtons.Right Then

            Dim sIndex AsInteger = ListBox1.IndexFromPoint(e.X, e.Y)

            If sIndex <> -1 Then

                ListBox1.SelectedIndex = sIndex

                ListBox1.ContextMenuStrip = ContextMenuStrip1

            Else

                ListBox1.ContextMenuStrip = Nothing

            EndIf

        EndIf

5、 ListBox多选取值

应用ListBox1.SelectedItems为被选中的项目集合,每一项为DataRowView类型

        Dim ii, irc AsInteger

        Dim ll As DataRowView

        irc = ListBox1.SelectedItems.Count

        For ii = 0 To irc - 1

            ll = ListBox1.SelectedItems(ii)

            MsgBox(ll.Row(0).ToString())

         Next

6、 字符串转颜色值

Color.FromArgb(Convert.ToInt32("FFFFFFFF--ARGB", 16)) 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: