How to print from a DataGrind the current cell in which I am standing

0

I'm using this code but it does not work

private void imprimirCeldaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            r = new imprimirmanifiesto();
            int pos = 0;
            bool a = true;
            try
            {
                r.imprimir(dataGridView1.CurrentCell.Value.ToString());
            }
            catch (Exception q)
            {
                //MessageBox.Show("Verifique número de importación y seleccione un tipo");
            }
        }

Method to print

public class imprimirmanifiesto
    {
        public void imprimir(string dobleslash)
        {
            Process p = new Process();
            p.StartInfo = new ProcessStartInfo()
            {
                FileName = "C:\Users\bodega\Documents\Manifiestos\" + dobleslash + ".pdf",
                UseShellExecute = true,
                Verb = "printto",
                CreateNoWindow = true,
                WindowStyle = ProcessWindowStyle.Hidden,
                //Arguments = printer,
            };
            p.Start();
        }
    }
    
asked by Saul Salazar 24.09.2018 в 23:54
source

1 answer

2

To obtain the value of the cell over which you have the selection, you must use the following code:

DataGridView1.Rows[DataGridView1.CurrentRow.Index].Cells[DataGridView1.CurrentCell.ColumnIndex].Value.ToString();

You can, for example, assign this result to a variable type string , or print it in a MessageBox .

In your case, you should have the try as follows:

try
{
    r.imprimir(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[dataGridView1.CurrentCell.ColumnIndex].Value.ToString());
}
    
answered by 25.09.2018 / 01:05
source