You will need to implement a way to filter your data based on the selected ID and navigate through different ID's when your user clicks the 'NextButton' button -
using System;
using System.Data;
using System.IO;
using System.Windows.Forms;
namespace DataGridViewFilter_Sb9m
{
public partial class MainForm : Form
{
private DataTable fullDataTable;
private DataView filteredDataView;
private int currentRowIndex = 0;
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
string filename = theDialog.FileName;
using (StreamReader reader = File.OpenText(filename))
{
string[] columnnames = reader.ReadLine().Split('|');
fullDataTable = new DataTable();
foreach (string c in columnnames)
{
fullDataTable.Columns.Add(c);
}
string newline;
while ((newline = reader.ReadLine()) != null)
{
DataRow dr = fullDataTable.NewRow();
string[] values = newline.Split('|');
for (int i = 0; i < values.Length; i++)
{
dr[i] = values[i];
}
fullDataTable.Rows.Add(dr);
}
}
filteredDataView = new DataView(fullDataTable);
ShowDataAtIndex(currentRowIndex);
}
private void ShowDataAtIndex(int index)
{
if (index >= 0 && index < filteredDataView.Count)
{
DataRowView rowView = filteredDataView[index];
string selectedID = rowView["ID"].ToString();
dataGridView.DataSource = filteredDataView.ToTable();
currentIDLabel.Text = "Current ID: " + selectedID;
}
}
private void NextButton_Click(object sender, EventArgs e)
{
currentRowIndex++;
if (currentRowIndex >= filteredDataView.Count)
{
currentRowIndex = 0;
}
ShowDataAtIndex(currentRowIndex);
}
private void FilterButton_Click(object sender, EventArgs e)
{
string selectedID = filterTextBox.Text;
filteredDataView.RowFilter = $"ID = '{selectedID}'";
currentRowIndex = 0;
ShowDataAtIndex(currentRowIndex);
}
}
}