(1)在资源管理器中选择对应的控件,并在属性中设置“View”为“Details”。
(2)添加列标题
点击【添加】按钮,在右侧【Text】处修改为列标题
(3)设置整行选择和网格线,设置为true
(4)打开数据文件txt时,内容显示在Listview1中。
this.listView1.Items.Clear(); //先清空listview1中所有数据
OpenFileDialog oFD1 = new OpenFileDialog();
oFD1.InitialDirectory = "C:\\"; //显示初始目录,
oFD1.Filter = "txt files(*.txt)|*.txt|All files(*.*)|*.*"; //文件名筛选字符串
oFD1.FilterIndex = 2;
oFD1.RestoreDirectory = true;
//若用户在对话框中单击确定,则结果为DialogResult.OK
//否则结果为DialogResult.Cancel
if (oFD1.ShowDialog() == DialogResult.OK) //打开文件
{
MessageBox.Show("成功打开文件:" + oFD1.FileName); //显示选择的文件名
FileStream fs = new FileStream(oFD1.FileName, FileMode.Open); //需添加头文件system.IO
StreamReader s1 = new StreamReader(fs, Encoding.ASCII);
string sepatator = ","; //以逗号分割字符串
char[] cgap = sepatator.ToCharArray();
string[][] data = new string[100][];
for (int i = 0; i < 999; i++)
{
string str1 = s1.ReadLine(); //读取一行字符
if (str1 == null) break;
string[] str2 = str1.Split(cgap, StringSplitOptions.None); //基于数组中的字符将字符串拆分为多个子字符串
ListViewItem b = new ListViewItem(new string[] {
str2[0], str2[1], str2[2] });
listView1.Items.Add(b);
}
}
注:1. oFD1.InitialDirectory = “C:\”; //可以修改为常用目录
2.string sepatator = “,”; //以逗号分割字符串,也可以以空格分隔字符串,只要与数据文件相对应即可
3. ListViewItem b = new ListViewItem(new string[] { str2[0], str2[1], str2[2] }); //有几列便有几个str2[i]
(4)使用listview1中读入的数据进行计算
listview中的数据都是string格式,item.SubItems[i].Text,表示第i列listview中的数据,i从零开始,使用时根据需要进行类型转换。使用foreach循环遍历每一行
foreach (ListViewItem item in this.listView1.Items) //每一行
{
string name = item.SubItems[0].Text; //string类型无需转换
x1 = double.Parse(item.SubItems[1].Text); //转化为double
x2 = double.Parse(item.SubItems[2].Text);
/*================计算代码============================
============计算出a1,a2,a3,a4=========================
*/
ListViewItem b = new ListViewItem(new string[] {
name, a1.ToString("F6"), a2.ToString("F6"),a3.ToString("F6"),a4.ToString(),a5.ToString()});
listView2.Items.Add(b);
}
(5)将计算结果数据显示在Listview2中
ListViewItem b = new ListViewItem(new string[] {
name, a1.ToString("F6"),a2.ToString("F6"),a3.ToString("F6"),a4.ToString(),a5.ToString()});
listView2.Items.Add(b);
有几列数据都以==a.ToString(“F6”)==的格式转化为string形,再添加到ListViewItem b = new ListViewItem(new string[] { });
最后将b添加到listview2中即可。
(6)保存listview2中的数据
SaveFileDialog sFD1 = new SaveFileDialog();
sFD1.InitialDirectory = "C:\\";
sFD1.Filter = "txt files(*.txt)|*.txt|All files(*.*)|*.*"; //保存文件的格式
sFD1.FilterIndex = 1;
sFD1.RestoreDirectory = true;
if (sFD1.ShowDialog() == DialogResult.OK)
{
string s = "";
for (int m = 0; m <listView2.Items.Count; m++) //所有项的集合数
{
for (int n = 0; n < listView2.Items[m].SubItems.Count; n++) // 一个项的所有子项集合数
{
s += listView2.Items[m].SubItems[n].Text + " ";
}
s += "\r\n";
}
using(StreamWriter sw = new StreamWriter(sFD1.FileName))
{
sw.WriteLine(s); //在文件中添加文本
}
MessageBox.Show("成功保存文件:" + sFD1.FileName);
}
(7)清空
this.listView1.Items.Clear(); //只移除所有的项
this.listView1.Clear(); //从控件中移除所有项和列(包括列表头)
测试:
就拿杭电OJ上的第1003题开始吧,这题比原书要复杂一些。Problem DescriptionGiven a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum
1、打开Vivado 2018.32、点击菜单栏的"Tools",在下拉菜单中选择“Settings…”3、在左边的菜单栏点击“Text editor”,在第一行的“Current Editor”复选框中选择“Current Editor”(注意不是选择Notepad++)4、在Editor栏中填写notepad++的安装路径 + 空格 + [file name]注意:(1)安装路径中的斜杠是左斜杠,如果直接复制需要将右斜杠改为左斜杠,(2)一定要加空格5、点击"OK",即可完成配置_vivado2017 notepad++
编写一个简单的支持正则表达式的字符串匹配函数,简单的正则表达式如下:字符 含义c 匹配字符c. 匹配任意一个字符* 若一个字符后紧跟*,则匹配0个或多个此字符函数原型如下,参数regexp是待
作者:Matt McKinney(ArcBlock 市场副总裁)译者:陈俊(ArcBlock 公关副总裁)通过安装和部署开发者就绪的 Blocklet,ArcBlock 区块基石平台..._blocklet
Electron 是一个优秀的跨平台桌面应用程序开源库,目前接触 Electron 的开发者也越来越多。但是笔者发现,目前社区里缺少对初学者足够友好的入门教程来帮助初学者用 Electron 搭建一个完整的开发框架。为了解决这个问题,笔者将结合平时的一些 Electron 开发经验,渐近式的带领读者从零开始搭建一个完整的 Electron 应用。在这个教程中,笔者将使用 React 构建渲染进程。当然,读者也可以用其他框架来构建渲染进程,各种前端框架脚手架已经足够友好,所以这一点不用担心。阅读完这篇教程_electron demo
硬盘类型中PMR 和 SMR是什么?为什么更多人选择PMR硬盘?大数据时代的数据量呈指数级增长,预计每两年就会翻一番。硬盘作为一种经济高效的存储介质,在当今的存储数字世界中依然起着中流砥柱的作用。硬盘驱动器(HDD) 供应商竞相研发垂直磁性记录 (PMR) 和叠瓦式磁性记录 (SMR) 等新的磁录技术,以生产更大容量的硬盘。PMR,即垂直磁性记录俗称10代硬盘技术,由硬盘厂商巨头希捷..._pmr不一定不是smr
在startActivity后,调用overridePendingTransition方法,例如,一)实现淡入淡出的效果如下:startActivity(new Intent(SplashActivity.this, MainActivity.class));SplashActivity.this.finish();overridePendingTransition(andro_overridependingtransition
1.驱动:driver.c#include <linux/module.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/of.h>#include <linux/of_device.h>#include <linux/platform_device.h>#include <linux/fs.h>#include..._platform 驱动多个led
方法一:CButton *pBtn = (CButton *)GetDlgItem(IDC_BTN_TEST);if (pBtn->GetWindowText() == _T("开始")){ pBtn->SetWindowText(_T("停止"));}else{ pBtn->SetWindowText(_T("开始"));}_c++ button 描述文字
1022 Digital Library (30 point(s))A Digital Library contains millions of books, stored according to their titles, authors, key words of their abstracts, publishers, and published years. Each book is..._pat甲级1022
一、Linux应用程序基础(一)、应用程序与系统命令的关系 角色 系统命令 应用程序 文件位置 一般在/bin和/sbin目录中,或Shell内部指令 通常在/usr/bin、/usr/sbinusr、/local/bin、/usr/local/sbin目录中 主要用途 完成对系统的基本管理工作,例如IP配置工具 完..._linux安装程序管理
第一部分、计算机算法常用术语中英对照Data Structures 基本数据结构Dictionaries 字典Priority Queues 堆Graph Data Structures 图Set Data Structures 集合Kd-Trees 线段树Numerical Problems 数值问题Solving Linear Equations 线性方程组Bandwidth ...