How can I printpreview in my GridControl
DevExpress based on mainview.
Here is my code:
private void PrintPreview()
{
// Get your currently selected grid row
var rowHandle = gridView1.FocusedRowHandle;
// Get the value for the given column - convert to the type you're expecting
var obj = gridView1.GetRowCellValue(rowHandle, "NIK");
try
{
if (gridView1.RowCount <=0)
{
MessageBox.Show("DATA ROW KOSONG", "WARNING", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else
{
OracleDataAdapter adp = new OracleDataAdapter();
for (int i = 0; i < gridView1.DataRowCount; i++)
{
//connection
if (koneksi.koneksi.con.State == ConnectionState.Open)
{
koneksi.koneksi.con.Close();
}
koneksi.koneksi.con.Open();
tambah buka = new tambah();
OracleCommand cmd = new OracleCommand();
cmd.Connection = koneksi.koneksi.con;
adp = new OracleDataAdapter(@"SELECT * FROM V_KARYAWAN, KARYAWAN_GAMBAR WHERE V_KARYAWAN.NIK = KARYAWAN_GAMBAR.KARYAWAN_FK AND V_KARYAWAN.NIK = '" + obj + "'", koneksi.koneksi.con);
}
DataSet ds = new DataSet();
adp.Fill(ds, "V_KARYAWAN, KARYAWAN_GAMBAR");
kartu report = new kartu();
report.DataSource = ds.Tables[0];
report.ShowPreview();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
It was difficult for me how to solve this. I cannot take the value from GridControl
mainview because mycode just know about FocusedRowHandle
in GridControl
.
// Get your currently selected grid row
var rowHandle = gridView1.FocusedRowHandle;
// Get the value for the given column - convert to the type you're expecting
var obj = gridView1.GetRowCellValue(rowHandle, "NIK");
I was using oracle database.