频道直达 - 学院 - 下载 - 交易 - 特效 - 字库 - 手册 -排名-工具- 繁體
网页教学网站开发 设为首页
加入收藏
联系我们
建站搜索: 常用广告代码   用户注册 | 用户登陆
您当前的位置:中国建站之家 -> 网站开发设计技术教程 -> Asp.Net教程 -> 如何在DataGrid中添加ComboBox的方法

如何在DataGrid中添加ComboBox的方法

作者:未知  来源:转载  发布时间:2005-7-20 10:20:16  发布人:acx

减小字体 增大字体

有两中方法:

1.修改 ColumnStyles 属性的值.
2.在DataGrid里, 直接贴 Combo 控件. 如:

Public MyCombo As New ComboBox()
    Dim con As New
SqlConnection("server=myservername;uid=myid;pwd=mypassword;database=northwin
d")
    Dim daEmp As New SqlDataAdapter("Select * From Employees", con)

    Public ds As New DataSet()
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
        AddHandler MyCombo.TextChanged, AddressOf Ctrls_TextChanged
        'Fill ComboBox list.
        MyCombo.Name = "MyCombo"
        MyCombo.Visible = False
        MyCombo.Items.Clear()
        MyCombo.Items.Add("Sales Representative")
        MyCombo.Items.Add("Inside Sales Coordinator")
        MyCombo.Items.Add("Vice President, Sales")
        MyCombo.Items.Add("Sales Manager")
        MyCombo.Items.Add("Flunky")


        daEmp.Fill(ds, "Employees")

        'Set the RowHeight of the DataGrid to the height of the ComboBox.
        DataGrid1.PreferredRowHeight = MyCombo.Height

        DataGrid1.DataSource = ds

        DataGrid1.DataMember = "Employees"
        'Add ComboBox to the Control collection of the DataGrid.
        DataGrid1.Controls.Add(MyCombo)
    End Sub

    Private Sub DataGrid1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles DataGrid1.Paint
        If DataGrid1.CurrentCell.ColumnNumber = 3 Then
            MyCombo.Width = DataGrid1.GetCurrentCellBounds.Width
        End If
    End Sub

    Private Sub Ctrls_TextChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
        If DataGrid1.CurrentCell.ColumnNumber = 3 Then
            MyCombo.Visible = False
            If DataGrid1.Item(DataGrid1.CurrentCell) & "" = "" Then
                SendKeys.Send("*")
            End If
            DataGrid1.Item(DataGrid1.CurrentCell) = MyCombo.Text
        End If
    End Sub

    Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles DataGrid1.CurrentCellChanged
        If DataGrid1.CurrentCell.ColumnNumber = 3 Then
            MyCombo.Visible = False
            MyCombo.Width = 0
            MyCombo.Left = DataGrid1.GetCurrentCellBounds.Left
            MyCombo.Top = DataGrid1.GetCurrentCellBounds.Top
            MyCombo.Text = DataGrid1.Item(DataGrid1.CurrentCell) & ""
            MyCombo.Visible = True
        Else
            MyCombo.Visible = False
            MyCombo.Width = 0
        End If
    End Sub

    Private Sub DataGrid1_Scroll(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.Scroll
        MyCombo.Visible = False
        MyCombo.Width = 0
    End Sub

    Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.Click
        MyCombo.Visible = False
        MyCombo.Width = 0
    End Sub

============================
更多资料请查MSDN.

将本文收藏到QQ书签与更多好友分享
[打 印]
[] [返回上一页] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
精彩推荐
热门文章
· 注册码大全二
· 注册码大全四
· 注册码大全一
· 要10G免费网络硬盘的请进..
· 通过google 赶快来赚美金..
· 注册码大全十
· 头像-qq头像(qq新头像)4..
· 让你轻松架设FTP服务器1..
· 注册码大全三
· 梦幻背景图片7
· 卡通动物图片6
· 网页制作素材-按钮素材2..
· 让你轻松架设FTP服务器5..
· 风景图片8
· 注册码大全九
· 让你轻松架设FTP服务器2..
关注此文读者还看过
· 大学生找工作有望通过“..
· fireworks MX教程:圆角三..
· 在RedHat9上构建小型的入..
· Oracle/Oracle Forms 的..
· 网站最令人讨厌的用户体..
· 高手进阶必读:Linux内核..
· Flash MX 编程深层次应用..
· 利用twig架设WebMail系统..
· 几个开源项目实体层实现..
· XML connector的讨论
· 3DsMAX实例制作:三维玻..
· 其他配制选项
· asp实现在web中显示电子..
· bbs树形结构的实现方法(..
· 设计聊天室
· HTML中Access Key(存取..
相关文章
· 如何在DB2里面更新执行计划..
· 如何在Dreamweaver中使用库..
· 如何在DataGrid控件中隐藏列..
· 如何在DataGrid控件中实现编..
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图 - 人才招聘
网站合作、内容监督、商务咨询:QQ: 9576619
Copyright ? 2005--2008 中国建站之家版权所有
粤ICP备05092265号