Solved

DataGridView in C#

Posted on 2008-06-15
3
856 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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)…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now