法拉克驱动板DCOH到55是什么意思?

10:29 提问
C#新手,创建DataGridView,如何手动输入数据并让其显示?
我创建了一个DataGridView,在里面设置了两列。
现在有一个textbox和一个button,我想实现当我每次在这个textbox里输入一个数字,按下button,可以在之前创建的DataGridView里插入新的一行,并在第一列里不断记录并显示我输入的这个数字,第二行留空。简而言之就是一个自己输入数字的记录器。
请问该怎么实现?
按赞数排序
//button事件里添加
DataGridViewRow gridRow=this.DataGridView1.Rows[gvSick.Rows.Add()];
gridRow..Cells[0].Value=this.textbox1.Text.Trim();
gridRow..Cells[1].Value="";
DataGridView的rows有add方法,然后如果是第一行,访问时就是Rows[0]第一列就是Rows[0].cells[0].value
具体代码 看下方,有问题的话再说。
public partial class Form1 : Form
public Form1()
InitializeComponent();
private List ssList=new List();
private void button1_Click(object sender, EventArgs e)
var str = textBox1.Text.Trim();
var ts = new TwoStr();
ssList.Add(ts);
dataGridView1.DataSource = ssL
class TwoStr
其他相似问题本帖子已过去太久远了,不再提供回复功能。查看: 4769|回复: 3
现用C#的datagridview控件生成表格,要求定时读取文件内容并刷新表格
该用户从未签到
现用C#的datagridview控件,在一个窗体下生成一个表格。要求表格根据按照设定的时间定时读取指定的文件,如果文件中有字符串“error”就闪烁红色报警。程序如下所示。
现在用timer控件可以实现“error”报警,但不能定时读取指定的文件。比如,设定的时间为 11:00,现在时间为 10:00,读取现在时刻的文件中的“error”信息了,程序继续运行,到设定时间时要读取 11:00对应的文件(假定此文件中也有“error”),要刷新报警。
我现在这个程序只能显示10:00的这个error,不能定时刷新使11:00这个也报警。只能在11:00以后重新打开程序运行。
求助,不胜感激!
[C#] 纯文本查看 复制代码using S
using System.Collections.G
using System.D
using System.D
using System.L
using System.T
using System.Windows.F
using System.IO;
namespace iGMASStest
public partial class WatchState : Form
int count = 0;
bool timerflag =
private bool bOrg =
public WatchState()
InitializeComponent();
private void WatchState_Load(object sender, EventArgs e)
//整体更改单元格字体属性
Font a = new Font(&GB2312&, 15);
dataGridView1.Font =
//定义表头
dataGridView1.ColumnHeadersVisible =
DataGridViewCellStyle columnHeaderStyle = new DataGridViewCellStyle();
columnHeaderStyle.BackColor = Color.B
columnHeaderStyle.Font = new Font(&Verdana&, 18, FontStyle.Bold);
dataGridView1.ColumnHeadersDefaultCellStyle = columnHeaderS
//表格自动填充
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.F
dataGridView1.ColumnCount = 5;
dataGridView1.Columns[0].Name = &监控业务&;
dataGridView1.Columns[1].Name = &预计执行时间&;
dataGridView1.Columns[2].Name = &完成情况&;
dataGridView1.Columns[3].Name = &业务运行状态报告&;
dataGridView1.Columns[4].Name = &对应日志文件&;
string strProgramExePath = Application.StartupP
string[] DoneOrNot = new string[6];
string[] state = new string[6];
string[] FileName = new string[6];
string[] strLogFilePath = new string[6];
string[] TimeGroup = new string[6] { & 08:00:00&, & 09:00:00&, & 10:00:00&, & 11:00:00&, & 12:00:00&, & 15:09:00& };
string[] FindFile = new string[6];
for (int i = 0; i & 6;i++ )
DateTime ModifTime = DateTime.Parse(TimeGroup[i]);
FindFile[i] = ModifTime.ToString(&yyyyMddHH&);
//各文件所在的路径
string startlogfile = Application.StartupPath+&\\Test&;
string DirName =
DirectoryInfo dir = new DirectoryInfo(DirName);
//如果非根路径且是系统文件夹则跳过
if (null != dir.Parent && dir.Attributes.ToString().IndexOf(&System&) & -1)
//取得所有文件
int[] flag2 = new int[6];//指定路径是否含有所需的文件标志,0“无”1“有”
int num = 0;
FileInfo[] finfo = dir.GetFiles();
for (int i = 0; i & 6; i++)
strLogFilePath[i] = startlogfile + &\\bac_drm_& + FindFile[i] + &.log&;
FileName[i] = &bac_drm_& + FindFile[i] + &.log&;
string fname = string.E
for (int j = 0; j & 6;j++ )
for (int i = 0; i & finfo.L i++)
fname = finfo[i].N
//判断文件是否包含查询名
if (fname.IndexOf(FileName[j]) & -1)
flag2[j] = 1;
// Console.WriteLine(finfo[i].FullName);
DateTime[] DT = new DateTime[6];
for (int i = 0; i & 6;i++ )
DT[i] = Convert.ToDateTime(TimeGroup[i]);
System.DateTime CT = DateTime.N
if (CT&DT[i])
DoneOrNot[i] = &未完成&;
state[i] = &未运行&;
if (flag2[i] == 1)
StreamReader sr = new StreamReader(strLogFilePath[i], Encoding.Default);
string strContent = sr.ReadToEnd();
sr.Close();//关闭文件
bool b = strContent.Contains(&error&);//判断是否有error
state[i] = &运行故障报警&;
DoneOrNot[i] = &已完成&;
state[i] = &正常运行结束&;
DoneOrNot[i] = &已完成&;
DoneOrNot[i] = &等待执行&;
state[i] = &等待运行&;
string[] row1 = new string[] { &数据质量评估&, TimeGroup[0], DoneOrNot[0], state[0], FileName[0] };
string[] row2 = new string[] { &快速产品质量评估&, TimeGroup[1], DoneOrNot[1], state[1], FileName[1] };
string[] row3 = new string[] { &超快速产品质量评估&, TimeGroup[2], DoneOrNot[2], state[2], FileName[2] };
string[] row4 = new string[] { &最终产品质量评估&, TimeGroup[3], DoneOrNot[3], state[3], FileName[3] };
string[] row5 = new string[] { &xx产品质量评估&, TimeGroup[4], DoneOrNot[4], state[4], FileName[4] };
string[] row6 = new string[] { &完好性产品质量评估&, TimeGroup[5], DoneOrNot[5], state[5], FileName[5] };
object[] rows = new object[] { row1, row2, row3, row4, row5, row6 };
dataGridView1.AllowUserToAddRows =
// TEST2.dataGridView1
foreach (string[] rowArray in rows)
dataGridView1.Rows.Add(rowArray);
int ss = dataGridView1.Rows.C
//定义行高
for (int i = 0; i & dataGridView1.Rows.C i++)
dataGridView1.Rows[i].Height = 75;
dataGridView1.AutoResizeColumnHeadersHeight();//定义表头高
//隔行变色
if (this.dataGridView1.Rows.Count != 0)
for (int i = 0; i & this.dataGridView1.Rows.C )
dataGridView1.Rows[i].DefaultCellStyle.BackColor = System.Drawing.Color.LightC
this.dataGridView1[3, 3].Style.ForeColor = Color.G//字体变色
dataGridView1.Rows[2].DefaultCellStyle.BackColor = Color.R//行变色
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllC
timer1.Enabled =
//业务监控颜色显示
for (int j = 2; j & 4; j++)
for (int i = 0; i & dataGridView1.Rows.C i++)
string s = &&;
s = dataGridView1.Rows[i].Cells[j].Value.ToString();
switch (s)
case &等待执行&: dataGridView1[j, i].Style.BackColor = Color.Y
case &等待运行&: dataGridView1[j, i].Style.BackColor = Color.Y
case &已完成&: dataGridView1[j, i].Style.BackColor = Color.LightG
case &正常运行结束&: dataGridView1[j, i].Style.BackColor = Color.LightG
case &运行故障报警&: dataGridView1[j, i].Style.BackColor = Color.OrangeR
case &未完成&: dataGridView1[j, i].Style.BackColor = Color.G
case &未运行&: dataGridView1[j, i].Style.BackColor = Color.G
private void timer1_Tick(object sender, EventArgs e)
for (int i = 0; i & this.dataGridView1.ColumnC i++)
for (int j = 0; j & this.dataGridView1.Rows.C j++)
if (this.dataGridView1[i, j].FormattedValue.ToString().IndexOf(&运行故障报警&) &= 0)
this.dataGridView1[i, j].Style.BackColor = Color.W
for (int i = 0; i & this.dataGridView1.ColumnC i++)
for (int j = 0; j & this.dataGridView1.Rows.C j++)
if (this.dataGridView1[i, j].FormattedValue.ToString().IndexOf(&运行故障报警&) &= 0)
this.dataGridView1[i, j].Style.BackColor = Color.R
bOrg = !bO
if (count == 3600)
timerflag =
if (timerflag)
timer1.Enabled =
//timer1.Start();
timer1.Interval = 500;//0.5s
timer1.Enabled =
(48.98 KB, 下载次数: 23)
10:25 上传
你把Load事件中的方法提取到一个方法里,在Timer的事件中每次执行调用一下。
&&&&&&&&&&&&&&&&
TA的每日心情开心3&天前签到天数: 249 天[LV.8]以坛为家I
你把Load事件中的方法提取到一个方法里,在Timer的事件中每次执行调用一下。
&&&&&&&&&&&&&&&&
该用户从未签到
你把Load事件中的方法提取到一个方法里,在Timer的事件中每次执行调用一下。
多谢站长,按照站长的方法,问题已经解决了!受教了,学习中……
&&&&&&&&&&&&&&&&
TA的每日心情开心3&天前签到天数: 249 天[LV.8]以坛为家I
多谢站长,按照站长的方法,问题已经解决了!受教了,学习中……
不客气,你这样代码没有多大问题,就是思路问题。你放在Load里只有开启时才执行一次,所以不会有效果。而放到Timer里是根据你设置的时间进行执行的。
&&&&&&&&&&&&&&&&
( 豫ICP备号-1)&&5760人阅读
winForm(5)
.net c#(12)
效果如下图:
主要代码如下:
using System.Collections.G
using System.D
using System.D
using System.L
using System.T
using System.Windows.F
namespace FuctionTest
& & public partial class FormProcessDataGridView : Form
& & & & BindingList&Employee& mEmployees = new BindingList&Employee&();
& & & & BindingSource mBbindingSource = new BindingSource();
& & & & public FormProcessDataGridView()
& & & & & & InitializeComponent();
& & & & private void FormInsertDataGridView_Load(object sender, EventArgs e)
& & & & & & mEmployees.Add(new Employee(&Tom&,23));
& & & & & & mEmployees.Add(new Employee(&Harry&,24));
& & & & & & mEmployees.Add(new Employee(&John&,26));
& & & & & & mBbindingSource.DataSource = mE
& & & & & & dataGridView1.Dock = DockStyle.F
& & & & & & dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllC
& & & & & & dataGridView1.AutoGenerateColumns =
& & & & & & AddColumns();
& & & & & & dataGridView1.DataSource = mBbindingS
& & & & & & dataGridView1.CellClick +=
& & & & & & & &new DataGridViewCellEventHandler(dataGridView1_CellClick);
& & & & private void AddColumns()
& & & & &&
& & & & & & DataGridViewTextBoxColumn nameColumn = new DataGridViewTextBoxColumn();
& & & & & & nameColumn.Name = &Name&;
& & & & & & nameColumn.DataPropertyName = &Name&;
& & & & & &&
& & & & & & DataGridViewTextBoxColumn ageColumn = new DataGridViewTextBoxColumn();
& & & & & & ageColumn.Name = &Age&;
& & & & & & ageColumn.DataPropertyName = &Age&;
& & & & & & DataGridViewButtonColumn insertColumn =
& & & & & & & new DataGridViewButtonColumn();
& & & & & & insertColumn.HeaderText = &&;
& & & & & & insertColumn.Name = &insertColumn&;
& & & & & & insertColumn.Text = &插入&;
& & & & & & insertColumn.UseColumnTextForButtonValue =
& & & & & & DataGridViewButtonColumn deleteColumn =
& & & & & & new DataGridViewButtonColumn();
& & & & & & deleteColumn.HeaderText = &&;
& & & & & & deleteColumn.Name = &deleteColumn&;
& & & & & & deleteColumn.Text = &删除&;
& & & & & & deleteColumn.UseColumnTextForButtonValue =
& & & & & & dataGridView1.Columns.Add(nameColumn);
& & & & & & dataGridView1.Columns.Add(ageColumn);
& & & & & & dataGridView1.Columns.Add(insertColumn);
& & & & & & dataGridView1.Columns.Add(deleteColumn);
& & & & private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
& & & & & &&
& & & & & &//增加空行
& & & & & & if (e.ColumnIndex==2)
& & & & & & {
& & & & & & & &mEmployees.Insert(e.RowIndex,new Employee(&&, 0));
& & & & & & }
& & & & & //删除当前行
& & & & & & if (e.ColumnIndex == 3)
& & & & & & {
& & & & & & & & mEmployees.RemoveAt(e.RowIndex);
& & & & & & }
& & & &列2输入格式验
& & & & private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
& & & & & & MessageBox.Show(e.Exception.Message.ToString());
& & & //对列1进行进一步验证
& & & & private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
& & & & & & if (e.ColumnIndex==0)
& & & & & & {
& & & & & & & & if (e.FormattedValue.ToString()==&123&)
& & & & & & & & {
& & & & & & & & & & MessageBox.Show(&不能为123&);
& & & & & & & & & & e.Cancel =
& & & & & & & & & & dataGridView1.CancelEdit();
& & & & & & & & }
& & & & & & & & else
& & & & & & & & {
& & & & & & & & & & e.Cancel =
& & & & & & & & }
& & & & & & }
public class Employee
& & & & public Employee(String name)
& & & & & & nameValue =
& & & & public Employee(String name,int age)
& & & & & & nameValue =
& & & & & & ageValue =
& & & & private String nameV
& & & & public String Name
& & & & & & get { return nameV }
& & & & & & set { nameValue = }
& & & & public Employee Self
& & & & & & get { }
& & & & private int? ageV
& & & & public int? Age
& & & & & & get { return ageV }
& & & & & & set { ageValue = }
& & & & & &&
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:167593次
积分:2365
积分:2365
排名:第14232名
原创:59篇
转载:17篇
译文:21篇
(2)(3)(4)(2)(9)(3)(2)(2)(1)(1)(2)(1)(2)(2)(11)(2)(3)(3)(2)(2)(3)(3)(1)(1)(2)(1)(1)(1)(2)(1)(2)(1)(1)(1)(3)(3)(2)(1)(2)(1)(3)(1)(1)(2)

我要回帖

更多关于 法拉克驱动板DCOH 的文章

 

随机推荐