Note that there are some explanatory texts on larger screens.

plurals
  1. PODatagridview, Only show unique values were Duplicate Cell Values C# 2005
    text
    copied!<p>I have some issues to display values but every time it duplicates the values in the datagridview, I’m using Microsoft Visual C# 2005 and framework 2.0.</p> <p>As I was programming this I found that inside the loop I need to check for duplicated values and count them and if a new value appears display the value and send a mail, I do have the code for the mail via smtp, but I need the duplicate values to be counted and eliminated only leaving the original cell and updating the rest, Can that be possible, this is the code that’s connected to the grid and the data generation I need serious help with this one, because I haven’t found the correct code on the web to do this job efficiently.</p> <pre><code> 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 &lt;= 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://&amp;&amp;&amp;&amp;(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); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload