Link to home
Start Free TrialLog in
Avatar of khyberman
khyberman

asked on

DataGridView in C#

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;
            }
Avatar of theplonk
theplonk
Flag of Australia image

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.
Avatar of khyberman
khyberman

ASKER

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;
            }
ASKER CERTIFIED SOLUTION
Avatar of graye
graye
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial