我真的很陌生,所以我很努力地直接爲我的問題得到答案。 我試圖在很多方面(YouTube,堆棧溢出,谷歌)找到我的問題的答案,但無法讓我的程序正常運行。C#DataGridView定義的表格數據從文件接收數據
我需要的程序是從m3u文件中獲取一個值到數據表的相應單元格中,而不是讀取並添加絕對一切。
我在網上找到的主要是如何讀取文本/ csv/excel和從文件本身導入所有數據,這不是我真正需要的或者我不明白如何實現我的使用的代碼,像那個問題:Reading from .txt file, then exporting data to DataGridView。
我已經定義了應該從m3u文件中「吸取」數據的單元。
文件m3u文件結構爲:
#EXTINF:-1 TVG-ID = 「」 TVG-NAME = 「====例1 ====」 TVG-標誌= 「」 基團-title =「」,====示例1 ====
thestreamingsource1.com
#EXTINF:-1 tvg-ID =「」tvg-name =「==== Example2 ====」tvg- logo =「」group-title =「」,====例子2 ====
thestreamingsource2.com
#EXTINF:-1 tvg-ID =「」tvg-name =「==== Example3 == ==「tvg-logo =」「group-title =」「,==== Example3 ====
thestreamingsource3.com
#EXTINF:-1 tvg-ID =「」tvg-name =「==== Example4 ====」tvg-logo =「」group-title =「」,==== Example4 ====
thestreamingsource4.com
我需要的程序,只得到了價值結構如下: TVG-ID(這沒關係,如果它是空的)。 tvg-name。 tvg-logo(沒關係,如果它是空的)。 組標題。
到目前爲止,我有字符串讀取文件和數據網格的所有內容,準備接受數據。
形式背後的代碼是:
public class ThisClass
{
DataGridView my_datagridview = new DataGridView();
DataTable my_datatable = new DataTable();
// Constructor and other methods are in this class,
// but not showed here...
private void btnRead_Click(object sender, EventArgs e)
{
// Some codes are hidden here...
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
string sFileName = openFileDialog1.FileName;
string[] alltext = File.ReadAllLines(sFileName);
foreach (string text_line in alltext)
{
// MessageBox.Show(text_line);
}
}
}
}
而且形式看起來像這樣:
我很抱歉,如果這個問題已經回答了,但我一直沒找到解。
很高興能幫到您。
謝謝。
請提供一個最小的工作示例,並改寫與你的問題。並且請直接在問題中提供所有信息(應回答問題時不需要點擊鏈接)。 – Jan
感謝她的病態工作 –
[將一個.txt文件放入DataGridView]可能的重複(https://stackoverflow.com/questions/7095359/putting-a-txt-file-into-a-datagridview) – Ramankingdom