请教winform中导出和批量删除!

zorro75317 2008-12-05 05:30:18
这个界面要实现导出和批量删除!

...全文
117 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
HDNGO 2008-12-05
  • 打赏
  • 举报
回复
[Quote=引用 18 楼 zorro75317 的回复:]
C# code
protected void AddExcel(DataSet ds)
{
DataTable dt = ds.Tables[0];

string fileName = Guid.NewGuid() + ".xls";
[/Quote]

嗯,这个比较简单,记得加office和excel的引用~
HDNGO 2008-12-05
  • 打赏
  • 举报
回复
哪些需要导出也可以用for循环判断一下checkbox的状态。。。
zorro75317 2008-12-05
  • 打赏
  • 举报
回复

protected void AddExcel(DataSet ds)
{
DataTable dt = ds.Tables[0];

string fileName = Guid.NewGuid() + ".xls";

Excel.Application excel = new Excel.ApplicationClass();

int rowIndex = 1;
int colIndex = 0;

excel.Application.Workbooks.Add(true);

foreach (DataColumn col in dt.Columns)
{
colIndex++;
excel.Cells[1, colIndex] = col.ColumnName;
}

foreach (DataRow row in dt.Rows)
{
rowIndex++;
colIndex = 0;
for (colIndex = 0; colIndex < dt.Columns.Count; colIndex++)
{
excel.Cells[rowIndex, colIndex + 1] = row[colIndex].ToString();
}
}

excel.Visible = false;
excel.ActiveWorkbook.SaveAs(fileName, Excel.XlFileFormat.xlExcel9795, null, null, false, false, Excel.XlSaveAsAccessMode.xlNoChange, null, null, null, null, null);
//excel.Save(fileName);

excel.Quit();
excel = null;

GC.Collect();//垃圾回收
}


是这一段吗?
HDNGO 2008-12-05
  • 打赏
  • 举报
回复
删除的话。。判断checkbox是不是true就成了吧~

for (int i = 0; i < dgv.Rows.Count; i++)
{
if (dgv.Rows[i].Cells[0].Value != null && (bool)dgv.Rows[i].Cells[0].Value == true)
{
//删除代码
}
}
zorro75317 2008-12-05
  • 打赏
  • 举报
回复
是导成excel
之前只做过web的,窗体的不会啊
HDNGO 2008-12-05
  • 打赏
  • 举报
回复
zorro75317 2008-12-05
  • 打赏
  • 举报
回复


jishengzu 2008-12-05
  • 打赏
  • 举报
回复
这贴怎么就我们3人 我刚去了下赌场 出来后就变成乞丐了在这里提醒大家不要赌钱,黑心庄家太多了
HDNGO 2008-12-05
  • 打赏
  • 举报
回复
导出excel?
zorro75317 2008-12-05
  • 打赏
  • 举报
回复
我太笨了,再传一遍
HDNGO 2008-12-05
  • 打赏
  • 举报
回复
表头画个全选的checkbox~

    class DGVColumnHeader : DataGridViewColumnHeaderCell
{
private Rectangle CheckBoxRegion;
private bool checkAll = false;

protected override void Paint(Graphics graphics,
Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
DataGridViewElementStates dataGridViewElementState,
object value, object formattedValue, string errorText,
DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle,
DataGridViewPaintParts paintParts)
{

base.Paint(graphics, clipBounds, cellBounds, rowIndex, dataGridViewElementState, value,
formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);

graphics.FillRectangle(new SolidBrush(cellStyle.BackColor), cellBounds);

CheckBoxRegion = new Rectangle(
cellBounds.Location.X + 3,
cellBounds.Location.Y + 2,
25, cellBounds.Size.Height - 4);


if (this.checkAll)
ControlPaint.DrawCheckBox(graphics, CheckBoxRegion, ButtonState.Checked);
else
ControlPaint.DrawCheckBox(graphics, CheckBoxRegion, ButtonState.Normal);

Rectangle normalRegion =
new Rectangle(
cellBounds.Location.X + 1 + 25,
cellBounds.Location.Y,
cellBounds.Size.Width - 26,
cellBounds.Size.Height);

graphics.DrawString(value.ToString(), cellStyle.Font, new SolidBrush(cellStyle.ForeColor), normalRegion);
}

protected override void OnMouseClick(DataGridViewCellMouseEventArgs e)
{
//Convert the CheckBoxRegion
Rectangle rec = new Rectangle(new Point(0, 0), this.CheckBoxRegion.Size);
this.checkAll = !this.checkAll;
if (rec.Contains(e.Location))
{
this.DataGridView.Invalidate();
}
base.OnMouseClick(e);
}

public bool CheckAll
{
get { return this.checkAll; }
set { this.checkAll = value; }
}
}
zorro75317 2008-12-05
  • 打赏
  • 举报
回复
zorro75317 2008-12-05
  • 打赏
  • 举报
回复
zorro75317 2008-12-05
  • 打赏
  • 举报
回复
我自己能看到啊?
jishengzu 2008-12-05
  • 打赏
  • 举报
回复
你可以先把你的图片传到你的csdn相册里边,成功后,你点那个图片的属性,里边有地址(url);
比如说我的头像:http://avatar.profile.csdn.net/8/4/1/1_dahai99007.jpg
你把他放到图片的完整地址输入框就好了。
HDNGO 2008-12-05
  • 打赏
  • 举报
回复
依然是QQ空间~你就不能换个地方传图?
jishengzu 2008-12-05
  • 打赏
  • 举报
回复
图片是XX啊
zorro75317 2008-12-05
  • 打赏
  • 举报
回复
还有这个界面也要实现导出和批量删除,该如何实现?

,该如何实现?
jishengzu 2008-12-05
  • 打赏
  • 举报
回复
看不到图 重发
HDNGO 2008-12-05
  • 打赏
  • 举报
回复
QQ空间哇

110,535

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧