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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T06:08:38+00:00 2026-05-12T06:08:38+00:00

I am struggling with the WinForms DataGridView. I have a class, that I use

  • 0

I am struggling with the WinForms DataGridView. I have a class, that I use as element to be displayed:

public class BorderFlowHistoryElement
{
    public string nodeTitles { get; set; }
    public double borderFlowRatio { get; set; }
    ...
}

I created a list of these elements:

List<BorderFlowHistoryElement> clusterHistory

which contains a list of thise elements, that should be displayed in my DataGridView. I bound the list at the DataSource of the Grid:

dataGridViewCluster.DataSource = clusterHistory;

Now the DataGridView displays the list. Now I want to format the columns which display the double values to display 5 digits. I tried it with:

dataGridViewCluster.Columns[1].DefaultCellStyle.Format = "n5";

but this has no effect on the column. Anyone knows, how I can do it right?
Additionally, I want to size the columnwidth to optimal fit for the largest entry.

Thanks in advance,
Frank

  • 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-12T06:08:38+00:00Added an answer on May 12, 2026 at 6:08 am

    I have replicated what you have done and I had no issue whatsoever. Have you validated your data to ensure that you can actually get the results that you want?

    Here is what I did just for your reference:

    private void button1_Click(object sender, EventArgs e)
        {
            IList<BorderFlowHistoryElement> clusterHistory = FillClusterHistory();
    
            dataGridView1.DataSource = clusterHistory;
    
            dataGridView1.Columns[1].DefaultCellStyle.Format = "n5";
    
            dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells);
    
        }
    
        private static IList<BorderFlowHistoryElement> FillClusterHistory()
        {
            IList<BorderFlowHistoryElement> clusterHistory = new   List<BorderFlowHistoryElement>();
    
    
            for(int i = 5000; i < 5020; i++)
            {
                BorderFlowHistoryElement element = new BorderFlowHistoryElement();
    
                element.nodeTitles = Guid.NewGuid().ToString();
    
                element.borderFlowRatio = i * 3.3.1415672467234823499821D;
    
                clusterHistory.Add(element);
            }
    
            return clusterHistory;
        }
    }
    
    public class BorderFlowHistoryElement
    {
        private string _NodeTitles;
        private double _BorderFlowRatio;
    
        public string nodeTitles
        {
            get { return _NodeTitles; }
            set { _NodeTitles = value;}
        }
    
        public double borderFlowRatio
        {
            get { return _BorderFlowRatio; }
            set { _BorderFlowRatio = value;}
        }
    }
    

    I hope that helps in some fashion. As you can see you can do the auto sizing as well.

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

Sidebar

Related Questions

Attempting/struggling to get registration and sign-up working within an active admin project. I have
Struggling with this one. I have set up a basic email/enquiry form for a
Struggling a bit today. I have the following method that returns a list of
Struggling with command line again, I have figure out that I can store the
I am struggling on something that, I am sure, should be easy. I have
Struggling with the following problem. I have an attribute that defines the name of
Struggling here... I am trying to have views displayed during specific periods in a
I am struggling to overcome this obstacle and I have high hopes that someone
I have an WinForms application with this Main Form : ICountRepository countRepository; public MainForm(ICountRepository
Struggling with styling the mouse over for a button ... I have managed to

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.