0
私は、テキストを検索してDataGridに追加する次の機能を持っています。RegExの一致からDataGridに重複する項目を避ける
try
{
string source = e.Result;
Regex re = new Regex(@"(\d+\.\d+\.\d+\.\d+):1400");
MatchCollection mc = re.Matches(source);
if (mc.Count > 0)
{
foreach (Match matches in mc)
{
int index = dataGridAllSonos.Columns.ToList().FindIndex(c => c.Header == matches.Groups[1].Value);
Console.WriteLine(index);
var data = new sonosDevice
{
sonosIP = matches.Groups[1].Value,
sonosName = "XX",
sonosRoom = "XX"
};
dataGridAllSonos.Items.Add(data);
}
}
}
catch (Exception ex)
{
if (ex.InnerException != null)
{
string err = ex.InnerException.Message;
Console.WriteLine(err);
}
}
線int index = dataGridAllSonos.Columns.ToList().FindIndex(c => c.Header == matches.Groups[1].Value);
電流はIP(最初の列)がすでにデータグリッドに存在する見つかったかどうかを確認することです。それを追加しないでください。
残念ながら、常に-1
が返されるので、IPが重複しているかどうかを確認できますか?
sonosDeviceクラス
public class sonosDevice
{
public string sonosIP { get; set; }
public string sonosName { get; set; }
public string sonosRoom { get; set; }
}
その行が列ヘッダーに検索します。これは、あなたの望むことですか?代わりに列の内容を検索する必要があります –
私は実際に列の値を探しています... – PrimuS