0

I have a dataGridView. Now I want to add new columns to this and then set value for this columns. This my code

DataGridViewColumn texBoxColumn = new DataGridViewColumn();
DataGridViewCell cell = new DataGridViewTextBoxCell();
texBoxColumn .Name = "River's name";
texBoxColumn .ValueType = typeof(string);
texBoxColumn .HeaderText = "name of river";
texBoxColumn .CellTemplate = cell;
dataGridView1.Columns.Insert(0, texBoxColumn );

And then, I add value for this columns by query dataBase

 for (int j = 0; j < dataGridView1.RowCount; j++)
        {
            dataGridView1[0, j].Value = "Hello";
        }

The problem is, this columns still null, don't show anything. Any help? Thanks so much.

Cong Tran
  • 1,448
  • 14
  • 30
  • Your code does various wrong things; so, please clarify what you want to accomplish exactly: calling this code to populate the DataGridView1 (all the rows in column "River's name") from the data you have under the class riverData. This is the FIRST TIME the DataGridView is populated (no information on it). Is this what you want? – varocarbas Nov 09 '13 at 08:50
  • Dear Cong you would like to add new column right i mean there are already few columns? and you want to one more column. please correct me if i'm wrong. – Sudhakar Tillapudi Nov 09 '13 at 08:50
  • hi guys. I have an dataGirdView and it still have displaying data. Now I want add a new column for this gridView and want it displaying something I want like "Hello" for example. – Cong Tran Nov 09 '13 at 09:00
  • Writing "Hello" in the new row `j` in the new column, `new_col`, is straightforward: `dataGridView1[new_col, j].Value = "Hello";` But your code doesn't do this; it takes the value from a different column (better: from column 1), what conditions the writing; also you are writing to column zero (first column everything), instead to the target column. – varocarbas Nov 09 '13 at 09:19
  • I insert it into column 0 or 1 or anything, It still not work. If I use the same code for another column (not just added) it show "Hello" for all of rows in column. But not work for this column just added http://i.upanh.com/rcsxen – Cong Tran Nov 09 '13 at 09:24
  • 1
    What you say does not make sense and, as said, your code depends upon factors we don't have any control on. If you want to get help quickly, write down easily reproduceable conditions (something anyone might write and get the exact behaviour you are getting); otherwise, you would have to find it by your own. Answer to the question, how to write "hello" to a given column/row has been answered. – varocarbas Nov 09 '13 at 09:42
  • Dear Cong it would help us to solve your problem easily if you can share the code with us. – Sudhakar Tillapudi Nov 09 '13 at 10:06
  • There is a high chance that the `songlist.ten_song;` is empty. You should try some debugging. I'm sure this problem can be solved with a little debugging. – King King Nov 09 '13 at 11:34
  • Hi guys, I just edit my code. And it still not working. Please help! – Cong Tran Nov 10 '13 at 08:10

0 Answers0