How to write the value in the specified on the screen cell in the dataGridView? enter image description here

So I got to Cells, then what to see? enter image description here

  • Value read from XML file - SVD102
  • dataGridView .Rows [y] .Cells [x] and see what is added there. Watch only after file upload (or after DataBind) - nick_n_a
  • What do you want to add there and for what? can it be easier to add one more column and write what you need there ?! - Bald

2 answers 2

This can be done in the cell's drawing event handler:

private void DataGridView_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.ColumnIndex == -1 && e.RowIndex >= 0) { e.PaintBackground(e.CellBounds, true); e.Graphics.DrawString("text", e.CellStyle.Font, Brushes.Black, e.CellBounds); e.Handled = true; } } 

However, as correctly suggested in the comments, it is better to add one more column.

     private void UpdateDGV() { dgvMain.Rows.Clear(); dgvMain.ColumnCount = 8; string[] name = { "a0", "a1", "a2"}; for(int i= 0; i < dgvMain.ColumnCount; i++){ dgvMain.Columns[i].Name = name[i]; dgvMain.Columns[i].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells; } double[] array = new double[]{76.5, -0.04, 0.04}; List<double> list = new List<double[]>(); list.add(array); foreach(var item in list) { string[] tmp = new string[item.lenghth]; for (int i = 0; i < item.lenghth; i++) { tmp[i] = item[i].ToString(); } dgvMain.Rows.Add(tmp); } }