linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘网络学院网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > asp.net >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·NetBPM工作流的一个示例:请假
·Office Web Components(OWC)绘
·asp.net正则表达式语法
·asp.net 2.0 ajax中使用PopupC
·Ado.Net读取Excel常见问题总结
·数据源为空时如何让GridView显
·如何让UpdatePanel支持文件上传
·C#.Net的常见面试试题和参考答
·asp.net ajax客户端编程+jquer
·Brettle.Web.NeatUpload.dll支
·ASP.NET使用Cookie
·ASP.NET DEMO 15: 同时支持行单
·如何使IE的后退按钮无效
·如何在ASP.NET中用OWC绘制图表
·asp.net:正确判断当前用户角色
最新文章
·Ajax Control Toolkit Animati
·讨论一下类似BlogEngine内一次
·使用CSS+SiteMap+UserControl+
·Asp.net中多彩下拉框的实现
·浅谈ASP.NET的Postback
·分清ASP.NET AJAX中的Extender
·Tip:在使用AjaxControlTookit
·有关注册DataItem的一些可能被
·IIRF(Ionic's Isapi Rewrite
·asp.net 客户端回调功能的实现
·关于控件部分的看法--读Progra
·为什么在vista上做开发
·如何封装JS和CSS文件为服务器端
·岂今我看过的最强的排序算法
·设计模式学习笔记之单件模式
Google
 
WinForm Datagrid结构剖析(三)使用代码
[ 作者:  加入时间:2007-11-27 17:01:15  来自:Linux联盟收集整理 ]
 接(三)类代码一文:(由于每篇文章的字数限制,不得不割开发,见谅!) AmxLinux联盟
   AmxLinux联盟
   '---------------------------------------------------------------------- AmxLinux联盟
   AmxLinux联盟
   ' 辅助方法 AmxLinux联盟
   AmxLinux联盟
   '---------------------------------------------------------------------- AmxLinux联盟
   AmxLinux联盟
   Private ReadOnly Property DataGridTableGridLineWidth() As Integer AmxLinux联盟
   AmxLinux联盟
   Get AmxLinux联盟
   AmxLinux联盟
   If Me.DataGridTableStyle.GridLineStyle = DataGridLineStyle.Solid Then AmxLinux联盟
   AmxLinux联盟
   Return 1 AmxLinux联盟
   AmxLinux联盟
   Else AmxLinux联盟
   AmxLinux联盟
   Return 0 AmxLinux联盟
   AmxLinux联盟
   End If AmxLinux联盟
   AmxLinux联盟
   End Get AmxLinux联盟
   AmxLinux联盟
   End Property AmxLinux联盟
   AmxLinux联盟
   Private Sub EndEdit() AmxLinux联盟
   AmxLinux联盟
   InEdit = False AmxLinux联盟
   AmxLinux联盟
   Invalidate() AmxLinux联盟
   AmxLinux联盟
   End Sub AmxLinux联盟
   AmxLinux联盟
   Private Function GetText(ByVal Value As Object) As String AmxLinux联盟
   AmxLinux联盟
   If Value Is System.DBNull.Value Then Return NullText AmxLinux联盟
   AmxLinux联盟
   If Not Value Is Nothing Then AmxLinux联盟
   AmxLinux联盟
   Return Value.ToString AmxLinux联盟
   AmxLinux联盟
   Else AmxLinux联盟
   AmxLinux联盟
   Return String.Empty AmxLinux联盟
   AmxLinux联盟
   End If AmxLinux联盟
   AmxLinux联盟
   End Function AmxLinux联盟
   AmxLinux联盟
   Private Sub HideComboBox() ‘隐藏Combobox AmxLinux联盟
   AmxLinux联盟
   If Combo.Focused Then AmxLinux联盟
   AmxLinux联盟
   Me.DataGridTableStyle.DataGrid.Focus() AmxLinux联盟
   AmxLinux联盟
   End If AmxLinux联盟
   AmxLinux联盟
   Combo.Visible = False AmxLinux联盟
   AmxLinux联盟
   End Sub AmxLinux联盟
   AmxLinux联盟
   Private Sub RollBack() AmxLinux联盟
   AmxLinux联盟
   Combo.Text = OldVal AmxLinux联盟
   AmxLinux联盟
   End Sub AmxLinux联盟
   AmxLinux联盟
   Private Sub PaintText(ByVal g As Graphics, _ AmxLinux联盟
   AmxLinux联盟
   ByVal Bounds As Rectangle, _ AmxLinux联盟
   AmxLinux联盟
   ByVal Text As String, _ AmxLinux联盟
   AmxLinux联盟
   ByVal AlignToRight As Boolean) AmxLinux联盟
   AmxLinux联盟
   Dim BackBrush As Brush = New SolidBrush(Me.DataGridTableStyle.BackColor) AmxLinux联盟
   AmxLinux联盟
   Dim ForeBrush As Brush = New SolidBrush(Me.DataGridTableStyle.ForeColor) AmxLinux联盟
   AmxLinux联盟
   PaintText(g, Bounds, Text, BackBrush, ForeBrush, AlignToRight) AmxLinux联盟
   AmxLinux联盟
   End Sub AmxLinux联盟
   AmxLinux联盟
   Private Sub PaintText(ByVal g As Graphics, _ AmxLinux联盟
   AmxLinux联盟
   ByVal TextBounds As Rectangle, _ AmxLinux联盟
   AmxLinux联盟
   ByVal Text As String, _ AmxLinux联盟
   AmxLinux联盟
   ByVal BackBrush As Brush, _ AmxLinux联盟
   AmxLinux联盟
   ByVal ForeBrush As Brush, _ AmxLinux联盟
   AmxLinux联盟
   ByVal AlignToRight As Boolean) AmxLinux联盟
   AmxLinux联盟
   Dim Rect As Rectangle = TextBounds AmxLinux联盟
   AmxLinux联盟
   Dim RectF As RectangleF = RectF.op_Implicit(Rect) ' 转为RectangleF类型 AmxLinux联盟
   AmxLinux联盟
   Dim Format As StringFormat = New StringFormat() AmxLinux联盟
   AmxLinux联盟
   If AlignToRight Then AmxLinux联盟
   AmxLinux联盟
   Format.FormatFlags = StringFormatFlags.DirectionRightToLeft AmxLinux联盟
   AmxLinux联盟
   End If AmxLinux联盟
   AmxLinux联盟
   Select Case Me.Alignment AmxLinux联盟
   AmxLinux联盟
   Case Is = HorizontalAlignment.Left AmxLinux联盟
   AmxLinux联盟
   Format.Alignment = StringAlignment.Near AmxLinux联盟
   AmxLinux联盟
   Case Is = HorizontalAlignment.Right AmxLinux联盟
   AmxLinux联盟
   Format.Alignment = StringAlignment.Far AmxLinux联盟
   AmxLinux联盟
   Case Is = HorizontalAlignment.Center AmxLinux联盟
   AmxLinux联盟
   Format.Alignment = StringAlignment.Center AmxLinux联盟
   AmxLinux联盟
   End Select AmxLinux联盟
   AmxLinux联盟
   Format.FormatFlags = Format.FormatFlags Or StringFormatFlags.NoWrap AmxLinux联盟
   AmxLinux联盟
   g.FillRectangle(Brush:=BackBrush, Rect:=Rect) AmxLinux联盟
   AmxLinux联盟
   Rect.Offset(0, yMargin) AmxLinux联盟
   AmxLinux联盟
   Rect.Height -= yMargin AmxLinux联盟
   AmxLinux联盟
   g.DrawString(Text, Me.DataGridTableStyle.DataGrid.Font, ForeBrush, RectF, Format) AmxLinux联盟
   AmxLinux联盟
   Format.Dispose() AmxLinux联盟
   AmxLinux联盟
   End Sub AmxLinux联盟
   AmxLinux联盟
  End Class AmxLinux联盟
   AmxLinux联盟
  4. 类的使用 AmxLinux联盟
   AmxLinux联盟
  如何使用这个类呢?方法其实很简单,把它看成与DataGridTextBoxColumn或DataGridBoolColumn一样处理就行了。见下例:数据库名为Northwind.mdb AmxLinux联盟
   AmxLinux联盟
  Private Sub FrmDropDownColumn_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load AmxLinux联盟
   AmxLinux联盟
   AmxLinux联盟
   AmxLinux联盟
   Dim objCustomerCM As CurrencyManager AmxLinux联盟
   AmxLinux联盟
   Dim objCustomerTableStyle As DataGridTableStyle AmxLinux联盟
   AmxLinux联盟
   Dim objGridCol As DataGridColumnStyle AmxLinux联盟
   AmxLinux联盟
   Dim IntAvgCharWidth As Integer AmxLinux联盟
   AmxLinux联盟
   ' 新建一个DataSet对象 AmxLinux联盟
   AmxLinux联盟
   _CustomerDS = New DataSet() AmxLinux联盟
   AmxLinux联盟
   '新建一个DataTable对象 AmxLinux联盟
   AmxLinux联盟
   _StatesDT = New DataTable() AmxLinux联盟
   AmxLinux联盟
   '新建一个 DataGridTableStyle 对象 AmxLinux联盟
   AmxLinux联盟
   GridTableStyle = New DataGridTableStyle() AmxLinux联盟
   AmxLinux联盟
   '计算显示时平均每个字符的宽度 AmxLinux联盟
   AmxLinux联盟
   With Graphics.FromHwnd(Me.Handle).MeasureString(Text:="ABCDEFGHIJKLMNOPQRSTUVWXYZ", Font:=Me.Font) AmxLinux联盟
   AmxLinux联盟
   IntAvgCharWidth = CInt(.Width / 26!) AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   ' 建立与数据库的连接 AmxLinux联盟
   AmxLinux联盟
   _DB = New OleDbConnection() AmxLinux联盟
   AmxLinux联盟
   Try AmxLinux联盟
   AmxLinux联盟
   With _DB AmxLinux联盟
   AmxLinux联盟
   .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ AmxLinux联盟
   AmxLinux联盟
   "Data Source=c:\Northwind.mdb" AmxLinux联盟
   AmxLinux联盟
   .Open() AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   Catch dbError As OleDbException AmxLinux联盟
   AmxLinux联盟
   Stop AmxLinux联盟
   AmxLinux联盟
   End Try AmxLinux联盟
   AmxLinux联盟
   _DB.Close() AmxLinux联盟
   AmxLinux联盟
   ' AmxLinux联盟
   AmxLinux联盟
   '新生成一条SQL语句且在DataSet中新建一个用户表 AmxLinux联盟
   AmxLinux联盟
   StrSQL = "SELECT * FROM 客户 WHERE 国家=" & Chr(34) & "美国" & Chr(34) & " ORDER BY 客户ID ASC" AmxLinux联盟
   AmxLinux联盟
   Try AmxLinux联盟
   AmxLinux联盟
   With New OleDbDataAdapter(selectCommand:=New OleDbCommand(cmdText:=StrSQL, _ AmxLinux联盟
   AmxLinux联盟
   Connection:=_DB)) AmxLinux联盟
   AmxLinux联盟
   .Fill(dataSet:=_CustomerDS, srcTable:="Customers") AmxLinux联盟
   AmxLinux联盟
   .Dispose() AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   Catch dbError As OleDbException AmxLinux联盟
   AmxLinux联盟
   Stop AmxLinux联盟
   AmxLinux联盟
   End Try AmxLinux联盟
   AmxLinux联盟
   ' 同与下拉框内容相关的数据源进行连接 AmxLinux联盟
   AmxLinux联盟
   _DB = New OleDbConnection() AmxLinux联盟
   AmxLinux联盟
   Try AmxLinux联盟
   AmxLinux联盟
   With _DB AmxLinux联盟
   AmxLinux联盟
   .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _ AmxLinux联盟
   AmxLinux联盟
   "Data Source=c:\Northwind.mdb" AmxLinux联盟
   AmxLinux联盟
   .Open() AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   Catch dbError As OleDbException AmxLinux联盟
   AmxLinux联盟
   Stop AmxLinux联盟
   AmxLinux联盟
   End Try AmxLinux联盟
   AmxLinux联盟
   _DB.Close() AmxLinux联盟
   AmxLinux联盟
   ' 创建SQL语句 AmxLinux联盟
   AmxLinux联盟
   StrSQL = "SELECT * FROM States ORDER BY 国家名 ASC" AmxLinux联盟
   AmxLinux联盟
   Try AmxLinux联盟
   AmxLinux联盟
   With New OleDbDataAdapter(selectCommand:=New OleDbCommand(cmdText:=StrSQL, _ AmxLinux联盟
   AmxLinux联盟
   Connection:=_DB)) AmxLinux联盟
   AmxLinux联盟
   .Fill(dataSet:=_CustomerDS, srcTable:="国家") AmxLinux联盟
   AmxLinux联盟
   .Dispose() AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   Catch dbError As OleDbException AmxLinux联盟
   AmxLinux联盟
   Stop AmxLinux联盟
   AmxLinux联盟
   End Try AmxLinux联盟
   AmxLinux联盟
   AmxLinux联盟
   AmxLinux联盟
   With _CustomerDS.Tables AmxLinux联盟
   AmxLinux联盟
   objCustomerCM = CType(Me.BindingContext(.Item(Name:="Customers")), CurrencyManager) AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   '生成显示信息 AmxLinux联盟
   AmxLinux联盟
   With GridTableStyle AmxLinux联盟
   AmxLinux联盟
   .MappingName = "Customers" AmxLinux联盟
   AmxLinux联盟
   With .GridColumnStyles AmxLinux联盟
   AmxLinux联盟
   .Add(column:=New DataGridTextBoxColumn(objCustomerCM. _ AmxLinux联盟
   AmxLinux联盟
   GetItemProperties.Item(Name:="地址"))) AmxLinux联盟
   AmxLinux联盟
   With .Item(index:=0) AmxLinux联盟
   AmxLinux联盟
   .MappingName = "地址" AmxLinux联盟
   AmxLinux联盟
   .HeaderText = "地址" AmxLinux联盟
   AmxLinux联盟
   .Alignment = HorizontalAlignment.Left AmxLinux联盟
   AmxLinux联盟
   .Width = IntAvgCharWidth * 20 AmxLinux联盟
   AmxLinux联盟
   .NullText = String.Empty AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   _StatesDT = _CustomerDS.Tables.Item("国家") AmxLinux联盟
   AmxLinux联盟
   .Add(column:=New DataGridComboBoxColumn(DataSource:=_StatesDT, _ AmxLinux联盟
   AmxLinux联盟
   DisplayMember:=0, _ AmxLinux联盟
   AmxLinux联盟
   ValueMember:=0)) AmxLinux联盟
   AmxLinux联盟
   With .Item(index:=1) AmxLinux联盟
   AmxLinux联盟
   .MappingName = "国家" AmxLinux联盟
   AmxLinux联盟
   .HeaderText = "国家" AmxLinux联盟
   AmxLinux联盟
   .Alignment = HorizontalAlignment.Left AmxLinux联盟
   AmxLinux联盟
   .Width = IntAvgCharWidth * 10 AmxLinux联盟
   AmxLinux联盟
   .NullText = String.Empty AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   .Add(column:=New DataGridTextBoxColumn(objCustomerCM. _ AmxLinux联盟
   AmxLinux联盟
   GetItemProperties.Item(Name:="城市"))) AmxLinux联盟
   AmxLinux联盟
   With .Item(index:=2) AmxLinux联盟
   AmxLinux联盟
   .MappingName = "城市" AmxLinux联盟
   AmxLinux联盟
   .HeaderText = "城市" AmxLinux联盟
   AmxLinux联盟
   .Alignment = HorizontalAlignment.Left AmxLinux联盟
   AmxLinux联盟
   .Width = IntAvgCharWidth * 20 AmxLinux联盟
   AmxLinux联盟
   .NullText = String.Empty AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   With EntryGrid AmxLinux联盟
   AmxLinux联盟
   .CaptionText = String.Empty AmxLinux联盟
   AmxLinux联盟
   .DataSource = _CustomerDS AmxLinux联盟
   AmxLinux联盟
   .DataMember = "Customers" AmxLinux联盟
   AmxLinux联盟
   .TableStyles.Add(table:=GridTableStyle) AmxLinux联盟
   AmxLinux联盟
   End With AmxLinux联盟
   AmxLinux联盟
   End Sub AmxLinux联盟
   AmxLinux联盟
   AmxLinux联盟
   AmxLinux联盟
  致谢:本程序参考了网上的多个实现方案,在此向各位原作者表示感谢。 AmxLinux联盟
   AmxLinux联盟
  ---- AmxLinux联盟
   AmxLinux联盟
    声明:本文版权与解释权归韩睿所有,如需转载,请保留完整的内容及此声明。 Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
 ·datagrid技巧之一:代码控制选中行的颜色 览和打印  (2007-11-26 16:31:38)
 ·一些实用的Javascript代码  (2007-11-26 15:46:06)
 ·使用GDB进行代码覆盖率测试  (2007-11-24 19:26:28)
 ·延迟/定时/强制弹出窗口的JS代码  (2007-11-23 14:47:37)
 ·美丽网页特效及其代码汇编  (2007-11-23 14:43:42)
 ·任何浏览器都可以弹的HTML广告代码  (2007-11-23 14:04:06)
 ·Javascript屏蔽键盘的代码  (2007-11-23 13:38:31)
 ·检测字符的Javascript代码  (2007-11-23 12:34:12)
 ·javascript实现的计数器功能代码  (2007-11-23 12:17:27)
 ·将RTF格式的文件转成HTML并在网页中显示的代码  (2007-11-23 10:56:23)