Csharp/C#教程:C#处理datagridview虚拟模式的方法分享

本文实例讲述了C#处理datagridview虚拟模式的方法。分享给大家供大家参考。具体如下:

usingSystem; usingSystem.Collections.Generic; usingSystem.ComponentModel; usingSystem.Data; usingSystem.Drawing; usingSystem.Text; usingSystem.Windows.Forms; namespaceVirtualMode { partialclassVirtualModeForm:Form { privateList<DataObject>m_Data=newList<DataObject>(); privateList<bool>m_Visited=newList<bool>(); publicVirtualModeForm() { InitializeComponent(); m_Grid.CellValueNeeded+=OnCellValueNeeded; m_GetVisitedCountButton.Click+=OnGetVisitedCount; InitData(); InitGrid(); } privatevoidInitData() { for(inti=0;i<1000001;i++) { m_Visited.Add(false); DataObjectobj=newDataObject(); obj.Id=i; obj.Val=2*i; m_Data.Add(obj); } } privatevoidInitGrid() { m_Grid.VirtualMode=true; m_Grid.ReadOnly=true; m_Grid.AllowUserToAddRows=false; m_Grid.AllowUserToDeleteRows=false; m_Grid.ColumnCount=3; m_Grid.Rows.Add(); m_Grid.Rows.AddCopies(0,1000000); //Uncommentthenextlineandcommentoutthe //therestofthemethodtoswitchtodataboundmode //m_Grid.DataSource=m_Data; } privatevoidOnCellValueNeeded(objectsender, DataGridViewCellValueEventArgse) { m_Visited[e.RowIndex]=true; if(e.ColumnIndex==0) { e.Value=m_Data[e.RowIndex].Id; } elseif(e.ColumnIndex==1) { e.Value=m_Data[e.RowIndex].Val; } elseif(e.ColumnIndex==2) { Randomrand=newRandom(); e.Value=rand.Next(); } } privatevoidOnGetVisitedCount(objectsender,EventArgse) { intcount=0; foreach(boolbinm_Visited) { if(b)count++; } MessageBox.Show(count.ToString()); } privatevoidVirtualModeForm_Load(objectsender,EventArgse) { } } publicclassDataObject { privateintm_Id; privateintm_Val; publicintVal { get{returnm_Val;} set{m_Val=value;} } publicintId { get{returnm_Id;} set{m_Id=value;} } } }

希望本文所述对大家的C#程序设计有所帮助。

上述就是C#学习教程:C#处理datagridview虚拟模式的方法分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)! 您可能感兴趣的文章:GridView自动增加序号(三种实现方式)C#中datagridview的EditingControlShowing事件用法实例C#中GridView动态添加列的实现方法C#实现DataGridView控件行列互换的方法C#实现绑定DataGridView与TextBox之间关联的方法C#中DataGridView常用操作实例小结C#实现3步手动建DataGridView的方法asp.net中GridView数据鼠标移入显示提示信息C#中DataGridView动态添加行及添加列的方法GridView使用学习

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/906597.html

(0)
上一篇 2021年10月23日
下一篇 2021年10月23日

精彩推荐