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 6336881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:08:36+00:00 2026-05-24T19:08:36+00:00

I have been working on a form that presents some specific elements in a

  • 0

I have been working on a form that presents some specific elements in a Data Grid View. Everything was implemented, and working correctly; then I decided to change things. I need many different version of the this one specific form, so I created a base form that my other forms can derive from. When I implement the inheritance of this base form, the data is listed in reverse. In other words before I made the change the columns were listed (Question Number, Marked For Review, Is Answered) no though, for what ever reason the data is listed (Is Answered, Marked for Review, Question Number). The reason that this matters is that my code assumes the question number is the first row, and that information is used to look up and display that specific question.

The base form looks like this

public partial class DataFormBase : FormBase
{
    /// <summary>
    /// Initializes a new instance of the <see cref="DataFormBase"/> class.
    /// </summary>
    public DataFormBase()
    {
        InitializeComponent();

        DrawGUI();
    }

    protected virtual void PopulateDataGrid() {}

    protected virtual void dgvData_CellClick(object sender, DataGridViewCellEventArgs e){}

    private void dgvData_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
    {
        dgvData.ClearSelection();
    }
}

And the implementation looks like this

public partial class SessionReviewForm : Core.DataFormBase
{
    public QuestionSessionForm ParentSession 
    {
        get; set;
    }

    public Session Session
    {
        get; set;
    }

    public SessionPart SessionPart
    {
        get; set;
    }

    /// <summary>
    /// Shows the dialog form.
    /// </summary>
    /// <param name="session">The session.</param>
    /// <param name="sessionPart">The session part.</param>
    /// <param name="parent">The parent.</param>
    /// <returns></returns>
    public static DialogResult ShowDialogForm(Session session, SessionPart sessionPart, QuestionSessionForm parent)
    {
        // if any of the params are null get the hell out!
        if (session == null || sessionPart == null || parent == null)
            return DialogResult.None;

        // create the new form, and populate its params
        SessionReviewForm form = new SessionReviewForm()
        {
            Session = session,
            SessionPart = sessionPart,
            ParentSession = parent,
        };

        // populate the forms data grid
        form.PopulateDataGrid();

        form.Size = new System.Drawing.Size(400,400);

        // show the form
        return form.ShowDialog(parent);
    }

    /// <summary>
    /// Populates the data grid with the required information
    /// </summary>
    /// <param name="instance">The instance for the w</param>
    protected override void PopulateDataGrid()
    {
        // Get all of the questions that are marked for review
        SessionQuestions questionsToDisplay = SessionPart.SessionQuestions.GetMarkedForReview();

        // add to the list all of the questions that have not yet been answered
        questionsToDisplay.AddRange(SessionPart.SessionQuestions.GetNotAnswered());

        // create a list of objects for the data grid view
        List<SessionReviewData> objectList = new List<SessionReviewData>();

        // for each question in the session question list, populate a new member of
        // the object list
        foreach (SessionQuestion sq in questionsToDisplay)
        {
            SessionReviewData temp = new SessionReviewData
            {
                QuestionNumber = sq.Sequence + 1,
                MarkedForReview = sq.MarkForReview,
                IsAnswered = sq.IsAnswered
            };
            objectList.Add(temp);
        }

        // bind the data grid view to the object list
        dgvData.DataSource = objectList;

        // format the column headers so that they have a space between words
        for (int i = 0; i < dgvData.Columns.Count; i++)
        {
            dgvData.Columns[i].HeaderText = Utilities.AddSpacesToSentence(dgvData.Columns[i].Name);
        }
    }

    /// <summary>
    /// Handles the CellClick event of the dgvQuestions control.
    /// populates the parent form with the selected question
    /// then closes the form.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.Windows.Forms.DataGridViewCellEventArgs"/> instance containing the event data.</param>
    protected override void dgvData_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        // if the user selects the header column, then get out.
        if (e.RowIndex == -1)
            return;

        // send the question data to the parentSession form to display the question
        ParentSession.DisplayQuestionByIndex((int)(dgvData.Rows[e.RowIndex].Cells[0].Value) - 1);

        // close this form
        Close();
    }

Solved:
Turns out Narrange was alphabetizing my internal data structure, and that caused them to be listed in the wrong order.

  • 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-24T19:08:36+00:00Added an answer on May 24, 2026 at 7:08 pm

    Code that ‘assumes’ that something is going to be somewhere may cause you problems.

    Simple solution would be to add the columns yourself as long as you always want the same columns in a certain order;

    dataGridView1.AutoGenerateColumns = false;
    DataGridViewColumn column = new DataGridViewColumn();
            column.DataPropertyName = "Question Number";
            column.HeaderText = "Question Number";
    dataGridView1.Columns.Add(column);
    

    … so on and so forth for each column you want

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

Sidebar

Related Questions

I have been working on some legacy C++ code that uses variable length structures
I have an enquiry form on a site, which has been working for a
I have been working with a string[] array in C# that gets returned from
I have been working with Struts for some time, but for a project I
A set of forms (using Zend_Form) that I have been working on were causing
I've been working on creating a form that submits content into my database but
I have been working to build a complex data structure which would return a
I have been working on a shop that is built in Python on the
Ok, so I have been working a Mysql class. I am making a form
I have been working on a code that will grab the userName from the

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.