Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6180799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:54:32+00:00 2026-05-24T00:54:32+00:00

I’ve got a class that represents an XML file to be processed. I’ve created

  • 0

I’ve got a class that represents an XML file to be “processed”. I’ve created a BindingList of these objects and bound it to a DataGridView so the user (i.e. me) can “control” things a bit and “see” what’s happening. By default, the constructor assumes all files in the list will be “processed”:

public class InputFileInfo : INotifyPropertyChanged
{
    private bool processThisFile;
    public bool Process
    {
        get { return processThisFile; }
        set 
        {
            processThisFile = value;
            this.NotifyPropertyChanged("Process");
        }
    }
    public string FileName { get; set; }
    public int Rows { get; set; }
    public string Message { get; set; }
    // constructor
    public InputFileInfo(string fName)
    {
        Process = true;
        FileName = fName;
        Rows = 0;
        Message = String.Empty;
    }
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string name)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(name));
    }
}

The first column of the DGV called “Process” might become unchecked in which case I want to skip that file (i.e. row) and continue with the next. The last 2 columns of the DGV are intended to display the number of output Rows that were emitted out of the processed XML file and a place to put some sort of Message (such as “OK” or “error text”).

In short, I want the DataGridView to be the visual representation of the process, echoing results in 2 little columns and allowing the user to skip a row by unchecking it.

Clicking on a button starts the processing of the files in the DGV. Here is what I have sketched so far (seems to work but the DGV does not reflect changes made in fileInfo.Rows and fileInfo.Message):

—– EDIT-UPDATE: per David Hall’s suggestion, looping thru the BindingList (_filesToParse) is a good fix to this problem (working code follows):

private void btnProcess_Click(object sender, EventArgs e)
    {
        FileStream fs = new FileStream("output-file.txt", FileMode.Create);
        StreamWriter writer = new StreamWriter(fs);
        OutputColumnNamesAsFirstLine(writer);
        foreach (InputFileInfo fileInfo in _filesToParse)
        {
            if (fileInfo.Process == true)
            {
                try
                {
                    fileInfo.Rows = processFile(writer, fileInfo.FileName);
                }
                catch (Exception ex)
                {
                    log.Warn("Error processing DataGridView:\r\n", ex);
                }
            }
            else
            {
                fileInfo.Rows = 0;
                fileInfo.Message = "skipped";
            }
        }
        writer.Dispose();
        fs.Dispose();
        MessageBox.Show("All selected files have been processed.");
    }

What would be the best approach?

  • Loop through the BindingList ?
  • Loop through the DataGridView ?

I think what I need is “two-way” binding but I maybe not? Am I close?

—————–E D I T (UPDATE)—————-

Yes, the XML files already exist. Here is how that part works:

private void initializeFileList(string rootFolder) // populate grid with .xml filenames to be processed
    {
        String root = rootFolder;
        var result = Directory.GetFiles(root, "*.xml", SearchOption.AllDirectories)
                    .Select(name => new InputFileInfo(name))
                    .ToList();
        _filesToParse =  new BindingList<InputFileInfo>(result.ToList());
        dataGridView1.DataSource = _filesToParse;
        dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
        btnProcess.Visible = true;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:54:33+00:00Added an answer on May 24, 2026 at 12:54 am

    David Hall’s comment(s) gave me enough confidence to go in this direction:

    • leave the datagridview as is from the toolbox to the form (i.e. do NOT loop thru the DGV)
    • loop thru the BindingList collection

    I took a stab at this code and posted it above by EDITing the original post. The code works but the DGV does not reflect it properly.

    So, this question morphed into a different question about how to achieve 2-way binding for a datagridview which I opened in (this new thread):How to use a static utility method for property setters in a utility class

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i got an object with contents of html markup in it, for example: string
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I need to clean up various Word 'smart' characters in user input, including but
i want to parse a xhtml file and display in UITableView. what is the
I want to count how many characters a certain string has in PHP, but
I have a JSP page retrieving data and when single or double quotes are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.