小编lin*_*ini的帖子

将文件填充到C#windows窗体中的文件夹的列表框中

我是C#的新手,我有2个列表框l - > istBox1和listBox2,我想将文件夹中的文件加载到这些列表框中.我试过这样的: listBox1:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DirectoryInfo dinfo = new DirectoryInfo(@"C:\TestLoadFiles");
            FileInfo[] Files = dinfo.GetFiles("*.rtdl");
            foreach (FileInfo file in Files)
            {
                listbox1.Items.Add(file.Name);
            }

        }
Run Code Online (Sandbox Code Playgroud)

listBox2:

private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            DirectoryInfo dinfo = new DirectoryInfo(@"C:\TestLoadFiles");
            FileInfo[] Files = dinfo.GetFiles("*.dlz");
            foreach (FileInfo file in Files)
            {
                listbox2.Items.Add(file.Name);
            }
        }
Run Code Online (Sandbox Code Playgroud)

当我运行表单时,文件夹中的文件不显示???

c# visual-studio-2010 visual-studio winforms

6
推荐指数
1
解决办法
3万
查看次数

C#:'System.StackOverflowException'发生在mscorlib.dll中

在此输入图像描述 今天早上我突然测试了我的代码,我收到了这个错误.我不知道该怎么办,因为直到昨天晚上才有工作档案.

我检查Stackoverflow网站的解决方案,但解决方案基于原始代码,它是本地的.

我希望有人能告诉我这里有什么问题?有没有解决这个问题的方法?

c# stack-overflow visual-studio-2010 winforms

5
推荐指数
1
解决办法
1万
查看次数

关闭XDOCUMENT的实例

我收到了这个错误

该进程无法访问文件"C:\ test\Person.xml",因为它正由另一个进程使用.IOException是UnHandled

如何在文件中保存内容后关闭xml文件的实例?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;

namespace XmlAddDelRecord
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            LoadDatagrid();
        }

        private void LoadDatagrid()
        {
            try
            {
                XmlReader xmlFile;
                xmlFile = XmlReader.Create(filePath, new XmlReaderSettings());
                DataSet ds = new DataSet();
                ds.ReadXml(xmlFile);
                dataGridView1.DataSource = ds.Tables[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            } 
        }

        private const string filePath = @"C:\test\Person.xml";

        private void …
Run Code Online (Sandbox Code Playgroud)

c# xml winforms

5
推荐指数
1
解决办法
7851
查看次数

将多个 XSLT 文件转换为用于 2 个不同 xml 文件的单个 XSLT 文件

这是我的 xml 文件:

<?xml version="1.0" encoding="windows-1250"?>
<CONTACTS>
    <CONTACT>
        <FirstName>Ford</FirstName>
        <LastName>Pasteur</LastName>
        <EMail>pasteur.ford@yahoo.com</EMail>
    </CONTACT>
    <CONTACT>
        <FirstName>Jack</FirstName>
        <LastName>Sully</LastName>
        <URL>http://www.facebook.com/profile.php?id=1000474277</URL>
    </CONTACT>
    <CONTACT>
        <FirstName>Colombo</FirstName>
        <LastName>Chao</LastName>
        <EMail>chao.colombo@liberto.it</EMail>
    </CONTACT>
</CONTACTS>
Run Code Online (Sandbox Code Playgroud)

我在第一个版本的 xml 输出中使用了下面的 XSLT 文件。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="CONTACT">
        <xsl:copy>
               <Customer-ID>
               <xsl:value-of select="generate-id(.)"/> 
               </Customer-ID>
              <xsl:copy-of select="FirstName|LastName|URL"/>
              <Facebook-ID>
            <xsl:choose>
                <xsl:when test="URL">
                    <xsl:value-of select="substring-after(URL,'?id=')"/>
                </xsl:when>
                <xsl:otherwise>

                </xsl:otherwise>
            </xsl:choose>
        </Facebook-ID>
            <EMAILS>
                <xsl:apply-templates select="EMail"/>
            </EMAILS>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="EMail">
        <EMail> 
            <Type><xsl:value-of select="substring-before(
                    substring-after(.,'@'),
                    '.')"/>
            </Type>
            <Value><xsl:value-of select="."/></Value>
        </EMail> …
Run Code Online (Sandbox Code Playgroud)

xml eclipse xslt

3
推荐指数
1
解决办法
2379
查看次数

从所有datagridviews中删除空行

这样我就可以从一个datagridview中删除空行.

bool Empty = true;

            for (int i = 0; i < PrimaryRadGridView.Rows.Count; i++)
            {
                Empty = true;
                for (int j = 0; j < PrimaryRadGridView.Columns.Count; j++)
                {
                    if (PrimaryRadGridView.Rows[i].Cells[j].Value != null && PrimaryRadGridView.Rows[i].Cells[j].Value.ToString() != "")
                    {
                        Empty = false;
                        break;
                    }
                }
                if (Empty)
                {
                    PrimaryRadGridView.Rows.RemoveAt(i);
                }
            }
Run Code Online (Sandbox Code Playgroud)

我有大约6个datagridviews,我想删除所有的空行.

有没有办法从界面中的所有datagridviews删除空行?

c# datagridview winforms

2
推荐指数
1
解决办法
5279
查看次数

文本框验证错误提供程序未清除

如果按下/键入任何错误的字符,我必须向用户显示一个图标,所以我使用error_provider.

在我的情况下,如果error_provider是文本框中的有效数字,则它不会消失.什么是misatek?

 string text = t_LongitudeRadTextBox.Text;
bool hasDigit = text.Any(letter => Regex.IsMatch(t_LongitudeRadTextBox.Text, "^[0-9]$"));
// Call SetError or Clear on the ErrorProvider.
if (!hasDigit)
{
    errorProvider1.SetError(t_LongitudeRadTextBox, "Needs to contain a digit");
}
else
{
    errorProvider1.Clear();
}
Run Code Online (Sandbox Code Playgroud)

c# errorprovider

1
推荐指数
1
解决办法
4774
查看次数

无法一次捕获所有异常C#

我正在对一个xml文件进行去序列化,我正在尝试使用下面的代码捕获所有异常艺术,但它只捕获一个异常.我在这做什么错?

码:

StringBuilder exBuilder;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
    var fileName = openFileDialog1.FileName;
    mruOpenRseConfig.AddRecentFile(fileName);
    try
    {
        ConfigDeserialized = MyConfig.DeserializeFromXmlFile(fileName);

    }

    catch (Exception ex)
    {
        if (ex is DataConsistencyException ||
            ex is XmlException)
        {
            exBuilder.Clear();
            exBuilder.Append(ex.Message + Environment.NewLine);

            RichTextBox richTextBox = new RichTextBox();

            richTextBox.Text = exBuilder;
            richTextBox.Dock = DockStyle.Fill;


            Form richMessageBox = new Form
            {
                StartPosition = FormStartPosition.CenterScreen,
                ControlBox = true,
                Text = "Error in File",
                MaximizeBox = false,
                MinimizeBox = false
            };

            richMessageBox.Controls.Add(richTextBox);

            richMessageBox.ShowDialog();
            return;
        }
        throw;
    }
}
Run Code Online (Sandbox Code Playgroud)

c# exception xml-serialization richtextbox winforms

0
推荐指数
1
解决办法
123
查看次数