如何从Datagridviewcombobox列中“隐藏/消除”Entrys [英] How Do I 'Hide/Dissable' Entrys From An Datagridviewcomboboxcolumn

查看:126
本文介绍了如何从Datagridviewcombobox列中“隐藏/消除”Entrys的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的优点,



我正在寻找隐藏DrowDown Entrys的解决方案,所以我可以用我的代码选择值来填充组合框和用户只能使用有限的值。



 私人  Sub  Button1_Click_1(发件人作为系统。对象,e  As  System.EventArgs)_ 
句柄 Button1.Click
Dim source As DataTable()
source.Columns。添加( desc
source.Columns.Add( DataColumn( value GetType 整数)))

Dim 作为 DataRow = source.NewRow
row( desc)= 供用户使用
行( < span class =code-string> value)= 1
source.Rows.Add( 对象(){ 供用户使用 2 })
source.Rows.Add( New 对象(){ 不供用户使用1 4 })
source.Rows.Add( New < span class =code-keyword>对象(){ 不允许用户使用2 6 })



Dim combocol 正如 DataGridViewComboBoxColumn()
使用 combocol
.Name = combo
.DataSource = source
.ValueMember = value
.DisplayMember = desc
' 我在找东西喜欢:
' ############### ###############
' 。HideEntry(1)'索引
'
' 。HideEntry(4)'Value
'
' .HideEntry(不供用户使用1)'文字

' 所以用户只能选择'供用户使用'
结束 使用
DataGridView1.Columns.Add(combocol)

Dim 内容 As DataTable()
使用内容
.Columns.Add( col1
.Columns.Add( col2
.Rows.Add ( 字符串(){ < span class =code-string> hallo, hans})
.Rows.Add( New String (){ wie gehts })
结束 使用
DataGridView1.DataSource = Content

' 这应该对代码产生影响,但是对于用户来说应该是不可用的
DataGridView1.Rows( 2 )。单元格( combo)。值= 4

结束 Sub





谢谢为你的effords

最好的问候

Florian Reiter

解决方案

使用DataGridView1.Columns.Add上面的这一行(合并)



 ''' ''''这可以删除行
source.Rows( 1 )。删除()





 '  DataGridView1.Rows(2).Cells(combo)。Value = 4  
Me .DataGridView1.Rows( 1 )。单元格( 0 )。 ReadOnly = < span class =code-keyword> True


Dear Pros,

i'm looking for an Solution to hide DrowDown Entrys, so i can select Values with my code to fill the combobox with and the User can only use limited values.

Private Sub Button1_Click_1(sender As System.Object, e As System.EventArgs) _
Handles Button1.Click
    Dim source As New DataTable()
    source.Columns.Add("desc")
    source.Columns.Add(New DataColumn("value", GetType(Integer)))

    Dim row As DataRow = source.NewRow
    row("desc") = "for User to use"
    row("value") = 1
    source.Rows.Add(New Object() {"for User to use", 2})
    source.Rows.Add(New Object() {"Not for User to use 1", 4})
    source.Rows.Add(New Object() {"Not for User to use 2", 6})



    Dim combocol As New DataGridViewComboBoxColumn()
    With combocol
        .Name = "combo"
        .DataSource = source
        .ValueMember = "value"
        .DisplayMember = "desc"
        'i am looking for something like:
        '##############################
        '.HideEntry(1) 'Index
        'or
        '.HideEntry(4) 'Value
        'or
        '.HideEntry("Not for User to use 1") 'Text

        'so the User can only select 'for User to use'
    End With
    DataGridView1.Columns.Add(combocol)

    Dim Content As New DataTable()
    With Content
        .Columns.Add("col1")
        .Columns.Add("col2")
        .Rows.Add(New String() {"hallo", "hans"})
        .Rows.Add(New String() {"wie", "gehts"})
    End With
    DataGridView1.DataSource = Content

    'This should make to code but shoud be dissabled for the user use
    DataGridView1.Rows(2).Cells("combo").Value = 4

End Sub



Thank you for your effords
Best Regards
Florian Reiter

解决方案

Use this line above of DataGridView1.Columns.Add(combocol)

''''''' This can be remove the row
       source.Rows(1).Delete()



'DataGridView1.Rows(2).Cells("combo").Value = 4
       Me.DataGridView1.Rows(1).Cells(0).ReadOnly = True


这篇关于如何从Datagridviewcombobox列中“隐藏/消除”Entrys的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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