vb2005如何保存住datagridview的格式?

想飞的狼 2008-07-29 04:15:55
    Dim strdd As String = "select 种类,日期,票号,客户编码,客户全称,性质,此次应付 as 金额,经手人,操作员,审核人,审核时间 from " + ComboBox2.Text + "." + "dbo" + "." + "yfa where substring(票号,5,8)=convert(char(8),cast('" + DateTimePicker1.Value + "' as datetime),112)"

Dim sqldas As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter(strdd, LoginForm1.conn)
sqldas.MissingSchemaAction = MissingSchemaAction.AddWithKey
sqldas.Fill(dataset2, "sss")
datagridview2.datasource=dataset2.tables("sss")

以上代码datagridview读出数据集中的记录,我想知道如何保存住表格中每个字段的自定义的宽度及高度,使DATAGRIDVIEW重新登录时能保存住上次的格式设置?
...全文
242 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
atlasroben 2008-07-30
  • 打赏
  • 举报
回复
这些代码当然不能,我说思路,简单点的方法
当你窗体关闭的时候,dataGridView1.Columns[i].Width获取窗体中gridview每个列的宽度,然后保存到一个datatable中,然后再用这个datatable去存成xml到你程序的目录下面

每次你这个有grdview的窗体在打开之前,就去检查程序目录下面这个用来存放用户配置的文件,将里面的配置列宽读取出来,然后用this.dataGridView1.Columns[i].Width挨个设置!
想飞的狼 2008-07-30
  • 打赏
  • 举报
回复
这些代码就能让用户把自定义宽度的单元格保存住,使每次重新登录软件都可以随意更改上次的样式?
atlasroben 2008-07-30
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 yjqmaster 的回复:]
厉害,就这意思
有没有这方面的例子参考下?
[/Quote]
囧,这个描述得够简单了,代码里面不会有复杂的东西
加分我给你写个项目发给你^^
你最好自己写这些东西,毕竟高手都是练出来的:),代码都很简单的,会用到的技术我给你说下吧
datatable读取和存储xml,读取和设置datagridview的列属性
没了,简单,我支持你自己写,不懂的地方问我吧
想飞的狼 2008-07-30
  • 打赏
  • 举报
回复
厉害,就这意思
有没有这方面的例子参考下?
atlasroben 2008-07-29
  • 打赏
  • 举报
回复
仅仅是列宽就用简单的
this.dataGridView1.Columns[0].Width = 1000;
atlasroben 2008-07-29
  • 打赏
  • 举报
回复
设置他们的样式,你如果要记忆这些样式将他们保存到一个配置文件就行了,下次读取出来
msdn有详细的关于样式设置的说明以下为简单示例

创建和初始化新的 DataGridViewCellStyle 对象以供多个行和列使用。


DataGridViewCellStyle highlightCellStyle = new DataGridViewCellStyle();
highlightCellStyle.BackColor = Color.Red;

DataGridViewCellStyle currencyCellStyle = new DataGridViewCellStyle();
currencyCellStyle.Format = "C";
currencyCellStyle.ForeColor = Color.Green


设置特定行和列的 DefaultCellStyle 属性。
this.dataGridView1.Rows[3].DefaultCellStyle = highlightCellStyle;
this.dataGridView1.Rows[8].DefaultCellStyle = highlightCellStyle;
this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle =
currencyCellStyle;
this.dataGridView1.Columns["TotalPrice"].DefaultCellStyle =
currencyCellStyle;


msdn的示例
private void SetDefaultCellStyles()
{
this.dataGridView1.DefaultCellStyle.BackColor = Color.Beige;
this.dataGridView1.DefaultCellStyle.Font = new Font("Tahoma", 12);

DataGridViewCellStyle highlightCellStyle = new DataGridViewCellStyle();
highlightCellStyle.BackColor = Color.Red;

DataGridViewCellStyle currencyCellStyle = new DataGridViewCellStyle();
currencyCellStyle.Format = "C";
currencyCellStyle.ForeColor = Color.Green;

this.dataGridView1.Rows[3].DefaultCellStyle = highlightCellStyle;
this.dataGridView1.Rows[8].DefaultCellStyle = highlightCellStyle;
this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle =
currencyCellStyle;
this.dataGridView1.Columns["TotalPrice"].DefaultCellStyle =
currencyCellStyle;
}



想飞的狼 2008-07-29
  • 打赏
  • 举报
回复
不是,,就是能把每个字段的宽度能自定义,并且能保存住
hmilj245216 2008-07-29
  • 打赏
  • 举报
回复

你是想问同一条数据第二次绑定让它和第一次绑定显示一样的格式吗?
想飞的狼 2008-07-29
  • 打赏
  • 举报
回复
有人说用width


怎么搞?
整个例子呗!

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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