这是我关于stackoverflow的第一个问题,我是C#编程的新手,所以请耐心等待。我使用WPF创建了一个应用程序,其中我在数据网格中显示了扩展名为.rpt的文件列表。 datagrid包含文件名列表,datagrid中还有一个复选框列。单击按钮时,这些文件将从文件夹浏览器动态填充到网格中。当我点击第二个按钮(打印,因为我需要调用服务来打印所选文件)时,我仍然坚持要检索这些文件进行打印。
这是我到目前为止尝试过的代码段:
public partial class MainWindow : Window
{
public class ReportFile
{
public string Path { get; set; }
public string FileName { get; set; }
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string inputPath = AppDomain.CurrentDomain.BaseDirectory;
System.Windows.Forms.FolderBrowserDialog fldDlg = new System.Windows.Forms.FolderBrowserDialog();
fldDlg.SelectedPath = AppDomain.CurrentDomain.BaseDirectory;
DialogResult result = fldDlg.ShowDialog();
foreach (string str in Directory.GetFiles(fldDlg.SelectedPath))
{
ReportFile reportFile = new ReportFile();
reportFile.Path = str;
reportFile.FileName = System.IO.Path.GetFileName(str);
dataGrid1.Items.Add(reportFile);
}
}
private void button_Click_1(object sender, RoutedEventArgs e)
{
foreach (ReportFile drv in dataGrid1.SelectedItems.OfType<ReportFile>())
{
if (drv != null)
{
DataRow row = drv.Row;
Title = row.ItemArray[3].ToString();
System.Windows.MessageBox.Show(Title.ToString());
}
}
var TransactionFactory = new TransactionFactory();
var Transaction = TransactionFactory.NewTransactionString();
var EnvironmentValue = (string)cmbEnvironment.SelectedValue;
var CirieEngineServiceClientFactory = new CirieEngineServiceClientFactory(EnvironmentValue);
var CirieEngineServiceClient = CirieEngineServiceClientFactory.NewCirieEngineServiceClient();
var Form = new Cirie.Form()
{
Path = string.Empty,
Title = string.Empty
};
var PackageID = Convert.ToInt16(txtPackageID.SelectedText);
var Generation = Convert.ToInt16(txtGeneration.SelectedText);
var formList = new List<Cirie.Form>();
var stream = CirieEngineServiceClient.PrintFormCollection
(Transaction,
new Collection<Cirie.Form>(formList),
PackageID,
Generation
);
}
}
但是我不确定它是否正确,因为抛出异常:无法转换类型&#39; ReportFile&#39;输入&#39; System.Data.DataRowView&#39;
我非常感谢你帮助这个!
答案 0 :(得分:2)
您可以使用<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="" id="myform">
Enter Your Name:<input type="text">
<input type="hidden" value="storage.tricksbygoogle.com">
<input type="submit" value="Submit">
</form>
方法将OfType
转换为SelectedItems
个对象,然后访问ReportFile
类的任何属性:
ReportFile