Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

DataGridView in C#

Posted on 2008-06-15
3
872 Views
Last Modified: 2013-12-17
How can I change the Row Label in column 0 (the left most column)  in a DataGridView.  I am able to change all columns in a new row but the left most because it doesn't seem to have a label.  Here is a code snippet of what I got so far:  Thx

            public static DataTable Get()
            {
                DataTable table = new DataTable("tablePQ");
                DataColumn Coldt;
                DataRow Rowdt;
                foreach (string label in Enum.GetNames(typeof(TableLabelsPQ)))
                {
                    Coldt = new DataColumn();
                    Coldt.DataType = System.Type.GetType("System.String");
                    Coldt.ColumnName = label;
                    Coldt.AutoIncrement = false;
                    Coldt.Caption = label;
                    Coldt.ReadOnly = false;
                    Coldt.Unique = true;
                    table.Columns.Add(Coldt);
                    foreach (string inst in Enum.GetNames(typeof(Currencies)))
                    {
                        Rowdt = table.NewRow();
                        Rowdt["Symbol"] = inst;
                        table.Rows.Add(Rowdt);
                    }

                }


                return table;
            }
0
Comment
Question by:khyberman
3 Comments
 
LVL 8

Expert Comment

by:theplonk
ID: 21791178
Could you please clarify your question? Are you trying to change a column header text? Or, Are you try to create default values for a new row? Or, are trying to change values for a new row?

In your code, you have a the loop for creating a datatable row within the loop for creating the columns.
0
 

Author Comment

by:khyberman
ID: 21791231
Sorry the code was incorrect.  The below is the correct version.   I am trying to assign a value to the left most column in the row (which is colored grey),  I am not abkle to do that through column labels.  Thx
 public static DataTable Get()
            {
                DataTable table = new DataTable("tablePQ");
                DataColumn Coldt;
                DataRow Rowdt;
                foreach (string label in Enum.GetNames(typeof(TableLabelsPQ)))
                {
                    Coldt = new DataColumn();
                    Coldt.DataType = System.Type.GetType("System.String");
                    Coldt.ColumnName = label;
                    Coldt.AutoIncrement = false;
                    Coldt.Caption = label;
                    Coldt.ReadOnly = false;
                    Coldt.Unique = true;
                    table.Columns.Add(Coldt);
               
                }
                   foreach (string inst in Enum.GetNames(typeof(Currencies)))
                    {
                        Rowdt = table.NewRow();
                        Rowdt["Symbol"] = inst;
                        table.Rows.Add(Rowdt);
                    }


                return table;
            }
0
 
LVL 41

Accepted Solution

by:
graye earned 250 total points
ID: 21792933
If I'm following you, that's not a "real" column.... instead, that's part of the "row header" (the series of little grey boxes that go down the left-hand side).

I suggest you turn off the RowHeadeVisible feature to see if we're talking about the same thing.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.rowheadersvisible.aspx
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question