我想知道如何读取位于服务器上的多个(大约500-1000)个文本文件.到目前为止,我已经为只读取单个文本文件的程序编写了代码.
这是我目前正在阅读单个文件的方式.
public void button1_Click(object sender, EventArgs e)
{
// Reading/Inputing column values
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string[] fileLines = File.ReadAllLines(ofd.FileName);
Run Code Online (Sandbox Code Playgroud)
我想摆脱打开文件对话框,让程序自动读取位于服务器中的500-1000文本文件.
我正在思考一些事情
for (int i =0; i<numFiles; i++)
{
//just use string[] fileLines =File.ReadAllLines()
//how would i specify the path for multiple files?
}
Run Code Online (Sandbox Code Playgroud)
那么问题是:
之前刚刚发布,需要澄清一个属性。(注意我知道这个问题与其他问题类似,因此我尝试在别处寻找解决方案,但找不到适合这种情况的确切解决方案)。
我对编程很陌生,不知道如何DataGridView滚动到用户选择的行。我尝试使用FirstDisplayedScrollingRowIndex但出现以下错误:
错误:无法将类型“System.Windows.Forms.DataGridViewRow”隐式转换为“int”
当我尝试将用户选择的行带到 datagridview 的顶部时会发生这种情况:
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows[i]
Run Code Online (Sandbox Code Playgroud)
这是完整的代码:
String searchVal = textBox1.Text;
for (int i = 0; i < dataGridView1.RowCount; i++)
{
if (dataGridView1.Rows[i].Cells[0].Value != null && dataGridView1.Rows[i].Cells[0].Value.ToString().Contains(searchVal))
{
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows[i];
dataGridView1.Update();
}
}
Run Code Online (Sandbox Code Playgroud) 我想在将它们选中后立即将以下两列转换为整数(它们在SQlite数据库中作为文本放置).
string sql4 = "select seq, maxLen from abc where maxLen > 30";
Run Code Online (Sandbox Code Playgroud)
我想可能会这样做..(使用演员表)
string sql4 = "select cast( seq as int, maxLen as int) from abc where maxLen > 30";
Run Code Online (Sandbox Code Playgroud)
不确定它是否正确,因为我似乎得到语法错误.
我怎样才能将文本转换为double
我注意到工具和菜单条非常严格.
有没有办法改变工具条或menustrip的位置?我想在我的winforms应用程序的自定义位置有一个下拉菜单(我正在使用c#).
如果没有,我可以尝试其他任何下拉菜单类型组件吗?
我正在尝试从服务器读取1000个文本文件.(使用c#,winforms)
问题是我遇到了2个错误,我不知道它们出现的原因.
错误1)"}预期"2)"类型或命名空间定义":
对于错误1,我看到}}关闭方法,为什么会出现.同样对于错误2,一切都在命名空间中,为什么它出现?
码:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{ // Error1
public static void ProcessAllFilesUnderDirectory(string topLevelDirectory, string searchMask, Action<string> processFile)
{
var files = Directory.EnumerateFiles(topLevelDirectory, searchMask, SearchOption.AllDirectories);
foreach (var file in files)
processFile(file);
}
private static void ProcessAFile(string fileName)
{
var lines = File.ReadAllLines(fileName);
// perform processing.
}
public static void Main(params string[] args)
{
ProcessAllFilesUnderDirectory(@"\camis01srfs04\DATA\Stats Analysis Project\Sobeys Stats\Atlantic", "*.txt", ProcessAFile);
} …Run Code Online (Sandbox Code Playgroud) 我想要一个显示单词Seq(这是一个列名)的文本框,然后列出其下面的mylist中的值.到目前为止,列表中的值显示,但Seq没有显示
private void button7_Click(object sender, EventArgs e)
{
if (seq1)
{
textBox1.Text = " Seq"; // This guy doesn't showup in the textbox
foreach (object o in SeqIrregularities)
{
textBox1.Text = String.Join(Environment.NewLine, SeqIrregularities);
}
}
}
Run Code Online (Sandbox Code Playgroud)