我正在尝试将csv文件加载到datagridview,现在我想向datagridview添加过滤
怎么做?这是我读取和加载csv文件的方式
openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.Title = "Open CSV Files";
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
openFileDialog1.DefaultExt = "CSV";
openFileDialog1.Filter = "CSV files (*.csv)|*.csv|All files(*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
try
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string csvPath = openFileDialog1.FileName;
string rowValue;
// int rowValue = int.Parse(??);
string[] cellValue;
dataGridView1.Rows.Clear();
//dataGridView1.Columns.Clear();
if (System.IO.File.Exists(csvPath))
{
System.IO.StreamReader fileReader = new StreamReader(csvPath);
rowValue = fileReader.ReadLine();
cellValue = rowValue.Split(',');
for (int i = 0; i <= cellValue.Count() - 1; i++)
{
DataGridViewTextBoxColumn …Run Code Online (Sandbox Code Playgroud) 我用 C# 制作了一个 DataGradView,它允许我折叠和展开行。看起来像这样:

在启动时,我想折叠具有多个条目的所有客户。就像图中所示的那样。customers is < 10.000
如果总数需要customer is > 10.000几分钟才能完成,效果很好。
折叠所有客户的代码:
int number = 0;
int oldnumber = 0;
int parent = 0;
foreach (CustomDataGridViewRow row in dataGridView1.Rows)
{
try
{
number = int.Parse(row.Cells[1].Value.ToString());
if (number != oldnumber && int.Parse(dataGridView1.Rows[row.Index + 1].Cells[1].Value.ToString()) == number)
{
row.Is_expander = true;
parent = row.Index;
}
if (number == oldnumber)
{
row.hide(parent);
}
oldnumber = number;
}
catch { }
}
Run Code Online (Sandbox Code Playgroud)
我调用了必须折叠的 foreach 行row.hide(parent),它将可见性设置为 false 并保存父索引。
对于每个父行将绘制一个图标 …