在数据网格视图中编辑 [英] edit in datagrid view

查看:50
本文介绍了在数据网格视图中编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在列表框中输入了多个CSV文件,并将其加载到datagridview中
但是作为初学者,我已经遇到了这个问题.
1-我想用文本框中的一个值替换选中的多个单元格值
2-我想将每个文件保存在其自己的位置,而不是将整个数据网格保存在一个文件中,而是将要保存的每个文件的更改都保存在

I''ve enterd several CSV files into listbox and i''ve loadded them to a datagridview
but as a begainner i''ve faced this problems .
1- i want to replace multible selected cells values with one value in textbox
2- i want to save every single file in it''s own location not the whole datagrid in one file but every file with it''s changes to be saved
that''s it

推荐答案

1-这是我用来填充"具有相同值的单元格的代码.我填满剪贴板中的内容或最近复制的内容...但是您可以将其更改为文本框的.Text.
1 - Here is the code I use to "Fill" the cells that are selected with the same value. I fill with whatever is in the clipboard or whatever was recently copied...but you can change that to your textbox''s .Text.
If dgvOutput.SelectedCells.Count <> 0 AndAlso My.Computer.Clipboard.ContainsText Then
   For Each c As DataGridViewCell In dgvOutput.SelectedCells
      'Remove any carriage returns = Chr(10) and line feeds = Chr(13) before pasting into cell
         c.Value = My.Computer.Clipboard.GetText.Replace(Chr(10), String.Empty).Replace(Chr(13), String.Empty)
   Next
End If



2-解决方案取决于您如何设置项目.您是否只有一个网格,并且每当用户更改列表框时,您使用该文件的数据加载网格?如果是这样,您如何将更改保存在内存中?例如,如果我查看文件A并进行更改,然后查看文件B ...仍在跟踪我对文件A的更改的信息在哪里?也许我对此想念您的问题.您在保存文件时遇到了什么困难?



2 - The solution to this depends on how you have your project setup. Do you have just one grid and every time the user changes the listbox you load the grid with that file''s data? If so, how are you keeping the changes in memory? For example, if I look at file A and make a change, then look at file B...where is the information that is still tracking my change to file A? Or maybe I''m missing your question on this. What specifically are you having trouble with in saving the files?


谢谢男人,非常感谢您的帮助,
实际上我已经使用此代码替换了选定的值


thanks man really i appreciate your help ,
actually i''ve used this code to replace the selected values


Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    For Each cell As DataGridViewCell In DataGridView1.SelectedCells

        DataGridView1.Rows(cell.RowIndex).Cells(cell.ColumnIndex).Value = TextBox4.Text


    Next
    MessageBox.Show("Value replaced")
End Sub








第二个问题是杀了我

实际上我的项目就是这样
1-浏览文件夹并选择该文件夹和子文件夹中的所有csv文件
2- csv文件合并在列表框中列出
3-从列表框中选择文件,然后单击插入",将csv文件填充到datagridview中(因此一次将多个文件填充到datagridview中)
4-在datagridview中编辑已加载的csv文件
5-将datagridview导出到一个csv文件

---------------------------------------------我的一切都很好直到这里,但是.......

6-(((((通过使用列表框中的文件名和Bath将更改保存到自己的每个单独的csv文件中)))现在这是我的问题








the second problem is killing me

actually my project is like this
1- browse for folder and select all the csv files in the folder and sub folders
2- the csv files bathes are listed in the list box
3- selecting the files from listbox and clicking insert the csv file is populated into the datagridview ( so several files are populated into datagridview at once )
4- editing the loaded csv files in the datagridview
5- exporting the datagridview to one csv file

--------------------------------------------- everything is fine with me till here but .......

6- ((( saving the changes to every single csv file in it''s own place bye using the file name and bath from the listbox ))) this is my problem now


这篇关于在数据网格视图中编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆