datagrid问题

wubaiyong 2005-01-21 10:54:42
点击datagrid某条记录的列,怎样让他选择这条记录的整个一行。
...全文
89 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinahth 2005-01-21
  • 打赏
  • 举报
回复
Henry手记:WinForm Datagrid结构剖析
http://www.csdn.net/develop/read_article.asp?id=16086
http://www.csdn.net/develop/read_article.asp?id=16087
http://www.csdn.net/develop/read_article.asp?id=16088
你看,也许有帮助
landlordh 2005-01-21
  • 打赏
  • 举报
回复
主要:
AddHandler ac.TextBox.Enter, AddressOf TextBoxEnterHandler

Public Sub TextBoxEnterHandler(ByVal sender As Object, ByVal e As System.EventArgs)
Dim inner As Control = sender
inner.Visible = False
If DataGrid1.CurrentRowIndex >= 0 Then
DataGrid1.Select(DataGrid1.CurrentRowIndex)
End If
End Sub
landlordh 2005-01-21
  • 打赏
  • 举报
回复

'通用样式化Datagird
'Power by:landlordh
'调用:
' strHeaders() 里面改为自已需要的列名
' iWidths() 里面改为相对应的列宽
' inputnum 在样式化之前赋值
' style(DataGrid1, DataSet1.Tables("codes"))
'
'=================================================================

'列名,字段对应名
Public strHeaders() As String = {"编号", "时间", "主题", "内容"}
'列宽,为0隐藏(优先级低于inputnum),对应的列宽
Public iWidths() As Integer = {0, 70, 130, 0}
'显示几列,为空则显示所有,为0则隐藏所有
Public inputnum As String

Public Sub style(ByVal datagridname As DataGrid, ByVal dataname As DataTable)
Try
datagridname.DataSource = dataname
'dataname.DefaultView.AllowNew = False
'dataname.DefaultView.AllowEdit = False
Dim i As Integer
If Trim(inputnum) <> "" Then
Dim num As Integer
Try
num = CInt(Trim(inputnum))
Try
For i = 0 To iWidths.Length - 1
If i >= inputnum Then
iWidths(i) = 0
End If
Next
Catch ex As Exception
End Try
Catch ex As Exception
MsgBox("你输入的字符不符合要求")
End Try
End If
Dim ts As New DataGridTableStyle
ts.MappingName = dataname.TableName
ts.AlternatingBackColor = System.Drawing.Color.PapayaWhip
ts.BackColor = System.Drawing.Color.WhiteSmoke
ts.GridLineColor = System.Drawing.Color.Tan
ts.SelectionBackColor = System.Drawing.Color.LightSteelBlue
ts.SelectionForeColor = Color.Black
ts.RowHeaderWidth = 10
ts.PreferredRowHeight = 20
For i = 0 To dataname.Columns.Count - 1
Dim ac As New DataGridTextBoxColumn
'处理点击行
AddHandler ac.TextBox.Enter, AddressOf TextBoxEnterHandler
ac.HeaderText = strHeaders(i)
ac.MappingName = dataname.Columns(i).ColumnName
ac.TextBox.Width = iWidths(i)
ts.PreferredColumnWidth = ac.TextBox.Width
'哪列,i=第几列数-1
If i = 1 Then
ac.Format = "yyyy-mm-dd hh:mm:ss"
'ac.ReadOnly = True
'ac.NullText = ""
ac.Alignment = HorizontalAlignment.Center
End If
If i = 1 Or i = 2 Then
'ac.ReadOnly = True
'ac.NullText = ""
ac.Alignment = HorizontalAlignment.Center
End If
ts.GridColumnStyles.Add(ac)
Next
datagridname.TableStyles.Clear()
datagridname.TableStyles.Add(ts)
Catch ex As Exception
MessageBox.Show("格式化网格出错了")
End Try
End Sub

Public Sub TextBoxEnterHandler(ByVal sender As Object, ByVal e As System.EventArgs)
Dim inner As Control = sender
inner.Visible = False
If DataGrid1.CurrentRowIndex >= 0 Then
DataGrid1.Select(DataGrid1.CurrentRowIndex)
End If
'filltext()
End Sub

16,722

社区成员

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

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