1. 首页 > 电脑教程 > 一个DataGrid组例子

一个DataGrid组例子

namespace ITMBA.BusinessRules.CommonBaseClassBR.Dock{using System;using System.ComponentModel;using System.Data;using System.Drawing;using System.Collections;using System.Windows.Forms;using System.Data.SqlClient;///

/// DataGridBR重写了DataGrid组件/// public class DataGridBR : System.Windows.Forms.DataGrid{//创建数组private System.Windows.Forms.DataGrid [] _DataGrid;private System.Windows.Forms.Form tempForm;//DataGrid索引private int _index = 0;//设置当前操作DataGrid索引private int _CurrentIndex=0;//当前选择值private DataView _ParentDV;//操作的父DataGrid的视图private int _ParentRow;//操作的父DataGrid的行索引private int _ParentColumn;//操作的父DataGrid的列索引/// /// 操作的父DataGrid的视图/// public DataView ParentDV{get{return _ParentDV;}set{_ParentDV = value;}}/// /// 操作的父DataGrid的行索引/// public int ParentRow{get{return _ParentRow;}set{_ParentRow = value;}}/// /// 操作的父DataGrid的列索引/// public int ParentColumn{get{return _ParentColumn;}set{_ParentColumn = value;}}/// /// 构造函数/// /// 容器窗口/// 当前操作的视图/// 选择的行索引/// 选择的列索引/// 将创建DataGrid数目public DataGridBR(System.Windows.Forms.Form owner,DataView dv,int row,int column, int Num){_DataGrid = new DataGrid[Num];for(int i=0;i/// 当前操作DataGrid索引/// public int CurrentIndex{set{_CurrentIndex = value;}get{return _CurrentIndex;}}/// /// 初始化数据源/// /// 数据源public void AddSource(System.Data.DataView dv){if(dv.Count>0){_DataGrid[_index++].DataSource = dv;}}/// /// 取得已创建的DataGrid数目/// /// public int GetNumEntries(){return _index;}/// /// 允许数组式访问/// public System.Windows.Forms.DataGrid this[int index]{get{_DataGrid[index].Dock = DockStyle.Fill;_DataGrid[index].RowHeadersVisible = true;_DataGrid[index].CaptionVisible = false;_DataGrid[index].DoubleClick += new System.EventHandler(this.DataGridBR_DoubleClick);return _DataGrid[index];}set{_DataGrid[index] = value;}}/// /// 选择事件/// /// /// private void DataGridBR_DoubleClick(object sender, System.EventArgs e){DataView tempDV = (DataView)_DataGrid[CurrentIndex].DataSource;int Count = tempDV.Count;if(Count != 0){ //MessageBox.Show(_DataGrid[CurrentIndex].CurrentRowIndex.ToString());int tempNo = _DataGrid[CurrentIndex].CurrentRowIndex;DataSet ds = tempDV.Table.DataSet;//MessageBox.Show(ds.Tables[0].Rows[tempNo][0].ToString());DataSet ds0 = ParentDV.Table.DataSet;ds0.Tables[0].Rows[ParentRow][ParentColumn] = ds.Tables[0].Rows[tempNo][0].ToString();//MessageBox.Show("row:"+ParentRow.ToString()+",column:"+ParentColumn.ToString());tempForm.Close();}else{MessageBox.Show("没有记录被选中","信息提示",MessageBoxButtons.OK);} }}}

声明:希维路由器教程网提供的内容,仅供网友学习交流,如有侵权请与我们联系删除,谢谢。ihuangque@qq.com
本文地址:https://www.ctrlcv.com.cn/diannao/169323124510618.html