不在select中指定字段,datagrid怎么自动过滤?

jsjzzh 2004-11-30 10:03:03
在select中用*选择所有字段,而希望在datagrid中只显示其中的一些。不知如何实现。

还有一个小问题:怎样更改combobox的高度
...全文
100 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xxuu503 2004-12-01
  • 打赏
  • 举报
回复
感觉上认为浪费
浪费了dataset的资源
3tzjq 2004-12-01
  • 打赏
  • 举报
回复
第一个问题上面都说得很清楚了!
2:可以将ComboBox的DrawMode=OwnerDrawVariable,也就说由自己重绘项,这样它的宽度会稍高些;
不想这样的效果就将DropDownStyle=ComboBoxStyle.Simple,这样就能要多高有多高了!如果还不是你要的效果,那么就考虑使用别的控件。
alphaqxm 2004-12-01
  • 打赏
  • 举报
回复
把列宽设为0就行了。
haoztao 2004-12-01
  • 打赏
  • 举报
回复
如楼上!
landlordh 2004-12-01
  • 打赏
  • 举报
回复
Private Sub style()
Try
Dim strHeaders() As String = {"编号", "添加时间", "代码主题", "代码内容"} '中文列名
Dim iWidths() As Integer = {0, 70, 130, 0} '设为0隐藏显示
DataGrid1.DataSource = DataSet1.Tables("codes")
DataSet1.Tables("codes").DefaultView.AllowNew = False
DataSet1.Tables("codes").DefaultView.AllowEdit = False
Dim i As Integer
Dim ts As New DataGridTableStyle
ts.MappingName = DataSet1.Tables("codes").TableName
ts.AlternatingBackColor = System.Drawing.Color.PapayaWhip
ts.BackColor = System.Drawing.Color.WhiteSmoke
ts.SelectionBackColor = System.Drawing.Color.LightSteelBlue
ts.SelectionForeColor = Color.Black
ts.RowHeaderWidth = 10
ts.PreferredRowHeight = 20

For i = 0 To DataSet1.Tables("codes").Columns.Count - 1
Dim ac As New DataGridTextBoxColumn
AddHandler ac.TextBox.Enter, AddressOf TextBoxEnterHandler
ac.NullText = ""
'ac.ReadOnly = True
ac.HeaderText = strHeaders(i)
ac.MappingName = DataSet1.Tables("codes").Columns(i).ColumnName
ac.TextBox.Width = iWidths(i)
ts.PreferredColumnWidth = ac.TextBox.Width
ts.GridColumnStyles.Add(ac)
If i = 1 Or i = 2 Then
ac.Alignment = HorizontalAlignment.Center
End If
Next
DataGrid1.TableStyles.Clear()
DataGrid1.TableStyles.Add(ts)
Catch ex As Exception
If MessageBox.Show("格式化网格出错了,继续操作可能会出错! " & Chr(10) & " 仍然继续吗?", "格式化出错", MsgBoxStyle.YesNo, MessageBoxIcon.Question) = MsgBoxResult.No Then
End
End If
End Try
End Sub
wangxt 2004-12-01
  • 打赏
  • 举报
回复
帮你顶
yangrenhuai 2004-11-30
  • 打赏
  • 举报
回复
1.修改tablestyles属性,在找到gridcolumnstyles属性修改

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧