?
Solved

DataGridView in C#

Posted on 2008-06-15
3
Medium Priority
?
889 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
[X]
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
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 1000 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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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.
Suggested Courses

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