如何在C#中将值从文本文件写入复选框 [英] How do I write values from text file to checkbox in C#
问题描述
我有一个用一些变量编写文本文件的程序,我需要将这些文本文件添加到一个清单中,然后将选定的文本文件发送到ftp服务器。
我将留下创建这些文本文件的代码:
I have a program that writes textfiles with some variables and I need to add those textfiles into a checklist and send the selected ones into an ftp server.
I'll leave here the code for creating those text files:
writer.WriteLine($"{numcont};{numenc};{numfatura};{data:dd/MM/yyyy};{valorStr};{zona};");
foreach (ItemTransactionDetail detail in transaction.Details)
{
var item = MyApp.DSOCache.ItemProvider.GetItem(
detail.ItemID,
MyApp.SystemSettings.BaseCurrency);
double taxRate = MyApp.DSOCache
.TaxesProvider
.GetTaxRateFromTaxableGroupID(
detail.TaxableGroupID,
"PRT",
"CON");
string barcode = item.BarCode;
writer.WriteLine($"{barcode};{taxRate};{precoantesdiscStr};{preconetStr};{quantidade};{bonus}");
}
我的尝试:
要填写清单,我已经测试了这个:
但这只是让我的清单空了
What I have tried:
To fill the checklist I've tested this:
But this just leaves my checklist empty
void Form1_Load(object EventArgs)
{
LoadFileNames();
}
void LoadFileNames()
{
string path = @"C:\Users\HP8200\Desktop\Faturas Teste";
string fileNameOnly = "";
// here you can change file extension according to your needs.
foreach (var item in System.IO.Directory.GetFiles(path,"*.txt"))
{
fileNameOnly = System.IO.Path.GetFileNameWithoutExtension(item);
// actually adding files names to checkbox listing
checkedListBox1.Items.Add(fileNameOnly);
}
}
推荐答案
< span class =code-string> {numcont}; {numenc}; {numfatura}; {data:dd / MM / yyyy}; {valorStr}; {zona};);
foreach (ItemTransactionDetail detail in transaction.Details)
{
var item = MyApp.DSOCache.ItemProvider.GetItem(
detail.ItemID,
MyApp.SystemSettings.BaseCurrency);
double taxRate = MyApp.DSOCache
.TaxesProvider
.GetTaxRateFromTaxableGroupID(
detail.TaxableGroupID,
PRT,
CON);
string barcode = item.BarCode;
writer.WriteLine(
"{numcont};{numenc};{numfatura};{data:dd/MM/yyyy};{valorStr};{zona};"); foreach (ItemTransactionDetail detail in transaction.Details) { var item = MyApp.DSOCache.ItemProvider.GetItem( detail.ItemID, MyApp.SystemSettings.BaseCurrency); double taxRate = MyApp.DSOCache .TaxesProvider .GetTaxRateFromTaxableGroupID( detail.TaxableGroupID, "PRT", "CON"); string barcode = item.BarCode; writer.WriteLine(
{条形码}; {TAXRATE}; {precoantesdiscStr}; {preconetStr}; {quantidade}; {奖金}跨度>);
}
"{barcode};{taxRate};{precoantesdiscStr};{preconetStr};{quantidade};{bonus}"); }
我的尝试:
要填写清单,我已经测试了这个:
但这只是让我的清单空了
What I have tried:
To fill the checklist I've tested this:
But this just leaves my checklist empty
void Form1_Load(object EventArgs)
{
LoadFileNames();
}
void LoadFileNames()
{
string path = @"C:\Users\HP8200\Desktop\Faturas Teste";
string fileNameOnly = "";
// here you can change file extension according to your needs.
foreach (var item in System.IO.Directory.GetFiles(path,"*.txt"))
{
fileNameOnly = System.IO.Path.GetFileNameWithoutExtension(item);
// actually adding files names to checkbox listing
checkedListBox1.Items.Add(fileNameOnly);
}
}
尝试将此行移动到自己的变量:
Try moving this line to its own variable:
foreach (var item in System.IO.Directory.GetFiles(path,"*.txt"))
to:
to:
var files = System.IO.Directory.GetFiles(path,"*.txt");
foreach (var item in files)
{
// do processing here
}
然后在它上面设置断点,跳过它,检查是否有文件名返回...我的猜测是没有文件,这就是列表的原因是空的......
Then set a breakpoint on it, step over it, and check that there are filenames returned... My guess is that there are no files and that is why the list is empty...
这篇关于如何在C#中将值从文本文件写入复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!