C# 选择菜单框时,必须显示一个文本框,以便用户可以输入一些值
我已经做了一个程序来完成这个程序该程序是一个csv解析器。 我需要这样做:当我选择“alfarithmitiko”时,会出现一个文本框(可能是您建议的其他内容),用户可以在其中输入一些单词,更具体地说是“医生”、“化学家”、“开发人员”、“技术员” 我将接受这些作业,并检查列中是否只有这些单词。例如,第三列是job,因此,它的字段中应该包含“医生”、“化学家”、“开发人员”、“技术人员”等词 多谢各位C# 选择菜单框时,必须显示一个文本框,以便用户可以输入一些值,c#,csv,C#,Csv,我已经做了一个程序来完成这个程序该程序是一个csv解析器。 我需要这样做:当我选择“alfarithmitiko”时,会出现一个文本框(可能是您建议的其他内容),用户可以在其中输入一些单词,更具体地说是“医生”、“化学家”、“开发人员”、“技术员” 我将接受这些作业,并检查列中是否只有这些单词。例如,第三列是job,因此,它的字段中应该包含“医生”、“化学家”、“开发人员”、“技术人员”等词 多谢各位 public partial class Form1 : Form {
public partial class Form1 : Form
{
ArrayList fileList = new ArrayList();
string stringforData;
public Form1()
{
InitializeComponent();
dataGridView1.Columns[0].ReadOnly = true;
}
private void button1_Click(object sender, EventArgs e)
{
// Anoigei to parathuro **BROWSE**
openFileDialog1.Title = "Epilexte Arxeio CSV Gia Elegxo ";
string filename = "";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
filename = openFileDialog1.FileName;
textBox1.Text = filename;
string line;
// Read the file and display it line by line.
//diavazei apo to textbox to path
System.IO.StreamReader file = new System.IO.StreamReader(textBox1.Text);
stringforData = file.ReadLine(); // Auth thn grammh thn ebala gia na mhn diabazei thn prwth grammh
while ((line = file.ReadLine()) != null)
{
// bazei stoixeia mesa ston pinaka
fileList.Add(line.Split(';'));
}
file.Close();
this.ToDataGrid();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.textBox2.Clear();
//************* COLUMN 2 SE STRING[] ************************************
string[] colB = new string[dataGridView1.Rows.Count];
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
colB[i] = Convert.ToString(dataGridView1.Rows[i].Cells[1].Value);
File.WriteAllLines("settings2.txt", colB);
}
//*************************************************************************
for (int i = 0; i < fileList.Count; i++)// perna mia mia tis grammes
{
string[] lineItems = (string[])fileList[i];// pinakas apo string
for (int j = 0; j < colB.Length; j++)
{
// Noumera-IDs
//textBox2.Text += "edw mphka, einai meta ta 2 for";// edw mpainei kanonika
if (colB[j] == "arithmos")
{
if (!arithmos(lineItems[j]))
textBox2.Text += "To stoixeio " + lineItems[j] + "\tsthn sthlh "+ j +" prepei na einai arithmos" + Environment.NewLine;
}
if (colB[j] == "alfarithmitiko")
{
// alfarithmitiko
if (!numword(lineItems[j]))
textBox2.Text += "To stoixeio " + lineItems[j] + " sthn sthlh " + j + " einai lathos grammeno" + Environment.NewLine;
}
//grammata
if (colB[j] == "grammata")
{
if (!word(lineItems[j]))
textBox2.Text += "To stoixeio " + lineItems[j] + " sthn sthlh " + j + " prepei na einai leksh" + Environment.NewLine;
}
}
}
// EDW THA APOTHUKEUW SE ARXEIO
}
//roufa ta dedomena apo thn deuterh sthlh kai bale ta se ena string[] to opoio legete stringFromGrid
//foreach (string a in stringFromGrid[])
// {
// if (stringFromGrid[a]=="arithmos")
// {
// if (!arithmos(kati me arrayList))
// textBox2.Text += "To stoixeio " + ?????????? + "\tsthn sthlh 7 prepei na einai arithmos" + Environment.NewLine;
// }
// if (stringFromGrid[a]=="grammata")
// {
// if (!word(kati me arrayList))
// textBox2.Text += "To stoixeio " + ?????????? + "\tsthn sthlh 7 prepei na einai arithmos" + Environment.NewLine;
// }
// if (stringFromGrid[a]=="alfarithmitiko")
// if (!numword(kati me arrayList))
// textBox2.Text += "To stoixeio " + ?????????? + "\tsthn sthlh 7 prepei na einai arithmos" + Environment.NewLine;
// }
// }
//if (textBox2.Text.Trim().Length == 0)
// {
// textBox2.Text = "den uparxei sfalma ";
// }
public void ToDataGrid()
{
string[] split = stringforData.Split(';');
foreach (string item in split)
{
dataGridView1.Rows.Add(item);
}
File.WriteAllLines("settings1.txt", split);
}
public bool arithmos(string a)
{
return Regex.IsMatch(a, (@"^\d*$"));
}
public bool word(string a)
{
return Regex.IsMatch(a, (@"^[a-zA-Z]*$"));
}
public bool numword(string a)
{
return Regex.IsMatch(a, (@"^[0-9a-zA-Z_]*$"));
}
公共部分类表单1:表单
{
ArrayList fileList=新建ArrayList();
字符串stringforData;
公共表格1()
{
初始化组件();
dataGridView1.Columns[0]。只读=true;
}
私有无效按钮1\u单击(对象发送者,事件参数e)
{
//Anoigei至帕拉图罗**浏览**
openFileDialog1.Title=“Epilexte Arxeio CSV Gia Elegxo”;
字符串filename=“”;
DialogResult=openFileDialog1.ShowDialog();
if(result==DialogResult.OK)
{
filename=openFileDialog1.filename;
textBox1.Text=文件名;
弦线;
//读取文件并逐行显示。
//diavazei apo至文本框至路径
System.IO.StreamReader file=新的System.IO.StreamReader(textBox1.Text);
stringforData=file.ReadLine();//验证语法
而((line=file.ReadLine())!=null)
{
//巴泽斯托伊西亚梅萨斯顿皮纳卡酒店
添加(line.Split(“;”);
}
file.Close();
这是.ToDataGrid();
}
}
私有无效按钮2\u单击(对象发送者,事件参数e)
{
this.textBox2.Clear();
//*************第2列SE字符串[]************************************
string[]colB=新字符串[dataGridView1.Rows.Count];
对于(int i=0;i
您需要绑定到DataGrid的CellEndEdit
事件,通过查看DataGridViewCellEventArgs
a找出哪个单元格已被编辑
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
var cell = dataGridView1[e.ColumnIndex, e.RowIndex];
if (cell.Value.Equals("alfarithmitiko"))
{
MyHiddenText.Visible = true;
}
}