Hi. (I am Portuguese) ********UPDATE******* Looks like I found the problem In the first for() there was a 1 instead of an i. I realized that after increasing zoom level. I apologize. ************** I am a new-by to Visual Studio and C# classes and I am trying to extract a GridView content to a CSV format file. Handling and processing fields seems not too difficult but the extraction is fighting me. I run the compiler, the form shows up, I fill the grid clicking the fill button, it fills OK but when I press the button to export, I get: System.NullReferenceException: 'Object reference not set to an instance of an object.' System.Windows.Forms.DataGridViewCell.Value.get returned null. In both similar lines: writer.Write(dataGridViewMotor1.Rows[i].Cells[j].Value.ToString());
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Stepping
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1\_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void btnSave01\_MouseClick(object sender, MouseEventArgs e)
{
TextWriter writer = new StreamWriter(@"H:\\proj\\\_Programacao\\\_Arduino\\ArduinoHM\\Stepper\_Polling\_us\\WinApp\\M01.txt");
for (int i = 0; 1 < dataGridViewMotor1.Rows.Count - 1; i++)
{
for (int j = 0; j < dataGridViewMotor1.Columns.Count; j++)
{
if (j == 0)
{
writer.Write(dataGridViewMotor1.Rows\[i\].Cells\[j\].Value.ToString());
}
else
{
writer.Write("," + dataGridViewMotor1.Rows\[i\].Cells\[j\].Value.ToString());
}
}
}
writer.Close();
MessageBox.Show("Data Exported");
}
private void btnFillTestData\_MouseClick(object sender, MouseEventArgs e)
{
// Line, Abs, Rel, X, C\_t, C\_i, C\_n, MinSpeed, MaxSpeed, Accel, Decel
dataGridViewMotor1.Rows.Add(1,0, 120,0,0,0,0, 10, 100, 0.9, 0.9 );
dataGridViewMotor1.Rows.Add(2,0,12