Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
I want to display a grid of lines on a panel with inputs from a datagridview control. With the number of grids, thus number of datagridview rows known, How can I populate a column in datagridview to hold labels for grids in such a way that the user names the starting grid's name(Say A or 1 or B1) and the remaining grids get named in ascending order to the starting grid name(Say B C D ... OR 2 3 4....or B2 B3 B4.....). I tried with a character array holding the 26 letters, like the following.
 
public char[] letters = new Char[26] { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
        public double grid_no_y;
        public double grid_no_x;
        public double grid_step_y;
        public double grid_step_x;
        public char xb;
        public char yb;
        GridSystem gs = new GridSystem();//A class holding the datagridview
for (int i = 0; i < gs.dataGridView1.ColumnCount; i++)
            {
                if (CB_X.Text=="A")//if the user chose to name the first grid A
                {
                    for (int j = 0; j < grid_no_x; j++)
                    {
                        if (i == 0)
                        {
                            gs.dataGridView1.Rows.Add();
                        }
 
                        string x = letters[j].ToString();
                        double y1 = j * grid_step_x;
 
                        string value = "0";
                        if (i == 0)
                            value = x;
                        else if (i == 1)
                            value = y1.ToString();
                        gs.dataGridView1[i, j].Value = value.ToString();
                    }
                }
 
But if the user wants more than 26 elements I get an error. Besides that It does not allow for flexibility of the user(i.e. the user is forced to name the first grid either A or 1) and I want the user to be able to start with any alphanumeric he desires.
 
I meant the datagridview entries themselves and not the naming of the column/row headers. Some thing of this type:
Column 1 Column2
Grid Name X-Coordinate
F 5
G 10
H 15
I 20
J 30
 
My concern is column 1 of the datagridview. How can I populate beginning from the user specified starting Index( in the above case for example: F) up.
Posted 10-Jan-13 2:15am
Edited 16-Jan-13 4:20am
v2
Comments
jibesh at 10-Jan-13 19:50pm
   
you mean like the header in Excel ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 298
1 Sergey Alexandrovich Kryukov 181
2 Yogesh Kumar Tyagi 165
3 ChauhanAjay 156
4 Richard Deeming 150
0 Sergey Alexandrovich Kryukov 6,218
1 OriginalGriff 5,413
2 CPallini 2,473
3 Richard MacCutchan 1,627
4 Abhinav S 1,530


Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 16 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100