This is what i ended up doing.. it works :)
private void dataGridView1_DragLeave(ob
{
//MessageBox.Show("OnDragL
}
private void dataGridView1_MouseDown(ob
{
if (dataGridView1.DataSource != null)
{
// DataTable dt in ds.Tables
StringBuilder sbCSV = new StringBuilder();
string sep = string.Empty;
int intColCount = 0;
intColCount= dTable.Columns.Count;
foreach (DataRowView dr in dTable.DefaultView)
{
for (int x = 0; x < intColCount; x++)
{
sbCSV.Append(dr[x].ToStrin
if ((x + 1) != intColCount)
{
sbCSV.Append(",");
}
}
sbCSV.Append("\n");
}
string filePath = System.IO.Path.GetTempPath
//string color = strTables;
String fileName = System.IO.Path.Combine(fil
WriteFile(fileName, sbCSV);
try
{
DataObject data = new DataObject(DataFormats.Fil
dataGridView1.DoDragDrop(d
// lblMessage.Text = getFileName(fileName) + " was saved";
}
catch (Exception y)
{
}
}
}
Main Topics
Browse All Topics





by: redpipePosted on 2007-05-15 at 14:13:28ID: 19096384
I don't know how you should do this with drag and drop (you could perhaps catch if a dragdrop operation is occuring and execute the export if the mousepointer goes outside the borders of the current border)
dex].Value + ";"); ine);
But in order to export the data in the grid, you could do just loop through the values in the grid.
// Get all columnheaders
StringBuilder sb = new StringBuilder();
foreach (DataGridViewColumn col in dgv.Columns) {
sb.Append(col.HeaderText + ";");
}
// Get values in all rows and columns
foreach (DataGridViewRow row in dgv.Rows) {
sb = new StringBuilder();
if (row.IsNewRow) { continue; }
foreach (DataGridViewColumn col in dgv.Columns) {
sb.Append(row.Cells[col.In
}
sb.Append(Environment.NewL
}