Vb.net 如何在Datagridview中为图像动态交换字符串?
萨尔维特!在windows窗体中,我有一个空的Vb.net 如何在Datagridview中为图像动态交换字符串?,vb.net,datagridview,Vb.net,Datagridview,萨尔维特!在windows窗体中,我有一个空的datagridview,其中包含从csvfile加载的字符串。datagridview没有初始列集合。csv文件中有四列。在csv文件中,第1列和第2列的值为true或false。到目前为止,我能够完美地加载文本 我想做的是将字符串“true”或“false”更改为我资源中的图像(一个漂亮的绿色复选标记和一个红色的x) 我想保持csv文件文本不变,然后动态更改列 然后,当我将信息保存回csv文件时,必须将图像转换为文本字符串以容纳csv 谢谢所有能
datagridview
,其中包含从csvfile加载的字符串。datagridview
没有初始列集合。csv文件中有四列。在csv文件中,第1列和第2列的值为true
或false
。到目前为止,我能够完美地加载文本
我想做的是将字符串“true”或“false”更改为我资源中的图像(一个漂亮的绿色复选标记和一个红色的x)
我想保持csv文件文本不变,然后动态更改列
然后,当我将信息保存回csv文件时,必须将图像转换为文本字符串以容纳csv
谢谢所有能帮助我的人 萨维特!好吧,经过一番痛苦的折磨,我终于明白了 首先,我将列结构硬编码到表单中,而不是动态加载它。我永远不需要csv文件中有更多的列数据,所以这是我的一个选择。但这允许我精确地指定哪些列是图像列,哪些列是文本列,并允许我在VS的GUI设计器中完成所有这些 加载csv时,我创建了两个额外的图像列,并将其相应的数据值设置为不可见 稍后,当我保存csv文件时,我跳过图像行并保存数据行中的内容
Private Sub ImportCSV(ByVal whatgrid As DataGridView, ByVal whatfile As String)
Dim TextLine As String = ""
Dim SplitLine() As String
whatgrid.Rows.Clear()
Dim thisobject0 As Object
Dim thisobject1 As Object
If System.IO.File.Exists(whatfile) = True Then
Dim objReader As New System.IO.StreamReader(whatfile)
Do While objReader.Peek() <> -1
TextLine = objReader.ReadLine()
SplitLine = Split(TextLine, ",")
If SplitLine(0) = "false" Then thisobject0 = My.Resources.markfalse Else If SplitLine(0) = "true" Then thisobject0 = My.Resources.marktrue Else thisobject0 = My.Resources.blank
If SplitLine(1) = "false" Then thisobject1 = My.Resources.markfalse Else If SplitLine(1) = "true" Then thisobject1 = My.Resources.marktrue Else thisobject1 = My.Resources.blank
whatgrid.Rows.Add(thisobject0, SplitLine(0), thisobject1, SplitLine(1), SplitLine(2), SplitLine(3))
Loop
objReader.Close()
blankNewRow()
Else
MsgBox("File Does Not Exist")
End If
End Sub
Private子导入SV(ByVal whatgrid作为DataGridView,ByVal whatfile作为字符串)
Dim TextLine As String=“”
将分割线()设置为字符串
whatgrid.Rows.Clear()
将thisobject0设置为对象
将thisobject1设置为对象
如果System.IO.File.Exists(whatfile)=True,则
Dim objReader作为新System.IO.StreamReader(whatfile)
Do While objReader.Peek()-1
TextLine=objReader.ReadLine()
拆分行=拆分(文本行,“,”)
如果拆分行(0)=“false”,则thisobject0=My.Resources.markfalse;如果拆分行(0)=“true”,则thisobject0=My.Resources.marktrue;否则thisobject0=My.Resources.blank
如果拆分行(1)=“false”,则thisobject1=My.Resources.markfalse;如果拆分行(1)=“true”,则thisobject1=My.Resources.marktrue;否则thisobject1=My.Resources.blank
whatgrid.Rows.Add(thisobject0,拆分线(0),thisobject1,拆分线(1),拆分线(2),拆分线(3))
环
objReader.Close()
blankNewRow()
其他的
MsgBox(“文件不存在”)
如果结束
端接头