Csharp: listview control binding database from datatable

 listView1.GridLines = true;//显示行与行之间的分隔线
            listView1.FullRowSelect = true;//要选择就是一行
            listView1.View = View.Details;//定义列表显示的方式
            listView1.Scrollable = true;//需要时候显示滚动条
            listView1.MultiSelect = true; // 可以多行选择
            listView1.HeaderStyle = ColumnHeaderStyle.Clickable; 

            if (dt.Columns.Count > 0)
            {
                //表頭名
                foreach (DataColumn column in dt.Columns)
                {
                    listView1.Columns.Add(column.ColumnName);
                }

                int r = 0;
                //每一行
                foreach (DataRow row in dt.Rows) // Loop over the rows.
                {
                    ListViewItem item = new ListViewItem(row[0].ToString());
                    for (int i = 1; i < dt.Columns.Count; i++)
                    {
                        if (i == 2)//因是二進制,顯示不了
                        {
                            item.SubItems.Add("");
                        }
                        else
                        {
                            item.SubItems.Add(row[i].ToString());
                        }
                    }
                    listView1.Items.Add(item);
                   r++;

                }

            }
时间: 2024-10-23 01:34:51

Csharp: listview control binding database from datatable的相关文章

Csharp: Listview convert Datatable and ListView.Group count

/// <summary> /// 計算ListView各類子項ListViewGroup的數量 /// </summary> /// <returns></returns> private DataTable getNumber(ListView listview) { ArrayList alist = new ArrayList(); DataTable dt = new DataTable(); dt.Columns.Add("name&q

Csharp: TreeView Control

    // --------------------------------------------------------------------------------------------- #region // Copyright (c) 2004-2005, SIL International. All Rights Reserved. // <copyright from='2004' to='2005' company='SIL International'> // Copy

Using ListView control under Win32 API

该例子在我的资源里面可以下载到完全可以运行的源代码http://download.111cn.net/source/463257 Introduction This article is for those who did not find, any useful code examples and information regarding ListControl (ListView). For me, it was really hard to get a working code for

Oracle Database Control浏览器无法登录问题的解决

环境:Oracle11g+IE9 问题:Oracle Database Control浏览器无法登录 解决: 打开 浏览器,输入URL:https://127.0.0.1:1158/em或者https://localhost:1158/em 如果出现Internet Explorer cannot display the webpage,则按以下步骤解决: 1. 首先看看portlist.ini这个文件( 位于$Home\install\下)里的端口是你输入的URL里的端口. 我的配置文件内容如

Displaying ListView items - with class! by Rob Bir

Displaying ListView items - with class!  by Rob Birdwell I don't know about you, but I'm very fond of the ListView control - it's a very useful control to have around. Microsoft's .NET Common Language Runtime (CLR) provides much of the functionality

Displaying ListView items - with class!

I don't know about you, but I'm very fond of the ListView control - it's a very useful control to have around. Microsoft's .NET Framework provides much of the functionality you need to display data in a ListView. However, you're still left will some

Displaying ListView items - with class! by Rob Birdwell

Displaying ListView items - with class!  by Rob Birdwell I don't know about you, but I'm very fond of the ListView control - it's a very useful control to have around. Microsoft's .NET Common Language Runtime (CLR) provides much of the functionality

ASP.NET 3.5的ListView与CSS Friendly

之前在写CSS有关文章的时候,我就想写写如何使用ASP.NET控件能够更加CSS Friendly,更容易实现一些常见的页面布局pattern,然而之后就发现这并非那么容易的.说起来要让ASP.NET控件变得CSS Friendly很容易,直接使用ASP.NET 2.0 CSS Friendly Control Adapters就是了,然而事实并非如此简单. CSS Friendly Control Adapters的不足 首先请允许我对这个CSS Friendly Control Adapte

“Win10 UAP 开发系列”之 在MVVM模式中控制ListView滚动位置

原文:"Win10 UAP 开发系列"之 在MVVM模式中控制ListView滚动位置 这个扩展属性从WP8.1就开始用了,主要是为了解决MVVM模式中无法直接控制ListView滚动位置的问题.比如在VM中刷新了数据,需要将View中的ListView滚动到顶部,ListView只有一个ScrollIntoView()方法可以控制滚动的位置,但最好在VM中不要出现直接控制View的代码,需要通过其他的方式. 使用一个扩展属性即可实现: /// <summary> ///