1
我有一些問題來顯示值,但每次它重複datagridview中的值,我使用Microsoft Visual C#2005和框架2.0。Datagridview,只顯示唯一值重複單元格值C#2005
當我在編程時,我發現在循環內我需要檢查重複的值並計算它們,如果出現新值顯示值併發送郵件,我確實通過smtp爲郵件編寫代碼,但我需要重複的值進行計數和消除,只留下原始單元格和其餘的更新,這是可能的,這是連接到網格的代碼,我需要嚴格的幫助這個數據生成的代碼,因爲我避風港沒有在網上找到正確的代碼來有效地完成這項工作。
try
{
e.Result = "";
//int count1 = 0;
int val = 6000;
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("ComputerName", typeof(String))); //0
dt.Columns.Add(new DataColumn("IP", typeof(String))); //1
dt.Columns.Add(new DataColumn("MAC", typeof(String))); //2
dt.Columns.Add(new DataColumn("Descubierto", typeof(String)));
for (int a = 1; a <= val; a++)
{
counter.Text = Convert.ToString(a);
if (txtWorkGroupName.Text == "") return;
//DataTable dt = new DataTable();
//dt.Clear();
//3
//int i = 0;
try
{
// Datos del grupo WinNT://&&&&(Nombre del grupo de trabajo)
DirectoryEntry DomainEntry = new DirectoryEntry("WinNT://" + txtWorkGroupName.Text + "");
DomainEntry.Children.SchemaFilter.Add("Computer");
///*************************************************
/// Interacting with the pcs in the domain
///*************************************************
foreach (DirectoryEntry machine in DomainEntry.Children)
{
string strMachineName = machine.Name;
string strMACAddress = "";
IPAddress IPAddress;
DateTime discovered;
try
{
IPAddress = getIPByName(machine.Name);
}
catch
{
continue;
}//try/catch
///*************************************************
/// Get Mac
///*************************************************
strMACAddress = getMACAddress(IPAddress);
///*************************************************
/// discovered time
///*************************************************
discovered = DateTime.Now;
///*************************************************
/// Add the data to the datagridview
///*************************************************
DataRow dr = dt.NewRow();
dr[0] = machine.Name;
dr[1] = IPAddress;
dr[2] = strMACAddress;
dr[3] = Convert.ToString(discovered);
dt.Rows.Add(dr);
dgvComputers1.DataSource = dt;
dgvComputers1.Refresh();
///Using Unique doesent work, this was one of the solutions found
//dt.Columns(machine.Name).Unique = true;
//dt.Columns(IPAddress).Unique = true;
//dt.Columns(strMACAddress).Unique = true;
}//foreach loop
// DataView dv = new DataView();
// dv = dt;
Thread.Sleep(2000);
//dt = ((DataView)this.dgvComputers1.DataSource).Table;
//dt.WriteXml(@"testermac.xml");
}//try/catch
catch (Exception ex)
{
{
MessageBox.Show(ex.Message);
}
}
if (backgroundWorker2.CancellationPending)
{
e.Cancel = true;
return;
}
}
}
catch (NullReferenceException ex)
{
MessageBox.Show("error:" + ex);
//tbmessage.Text += "se ha producido un error: " + ex + Environment.NewLine;
//tbmessage.SelectionStart = tbmessage.Text.Length;
//tbmessage.ScrollToCaret();
}
catch (NoNullAllowedException ex)
{
MessageBox.Show("error:" + ex);
}
catch (AccessViolationException ex)
{
MessageBox.Show("error:" + ex);
}
}
完美的,善意的提醒,我不是一個程序員,這是我的論文的一部分....即時通訊建立一個遠程廣告managemet機器人的域管理員 – 2011-12-31 20:42:29
,那麼你可能想購買一本好書或找在互聯網上的好教程。加里有一個很好的答案,你又發佈了[這裏](http://stackoverflow.com/questions/8717898/datagridview-find-duplicate-rows-and-update-existing-data/8721553#8721553) – 2012-01-06 03:21:06