Solved

DataGridView in C#

Posted on 2008-06-15
3
863 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

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 …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

911 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

17 Experts available now in Live!

Get 1:1 Help Now