private void FillGrid(string name, BaseUtils.SortedListDoubleDuplicate <ISystem> csl) { dataGridViewNearest.Rows.Clear(); if (csl != null && csl.Any()) { SetControlText(string.Format("From {0}".Tx(this, "From"), name)); foreach (KeyValuePair <double, ISystem> tvp in csl) { double dist = Math.Sqrt(tvp.Key); // distances are stored squared for speed, back to normal. if (tvp.Value.Name != name && (checkBoxCube.Checked || (dist >= textMinRadius.Value && dist <= textMaxRadius.Value))) { int visits = discoveryform.history.GetVisitsCount(tvp.Value.Name, tvp.Value.EDSMID); object[] rowobj = { tvp.Value.Name, $"{dist:0.00}", $"{visits:n0}" }; int rowindex = dataGridViewNearest.Rows.Add(rowobj); dataGridViewNearest.Rows[rowindex].Tag = tvp.Value; } } } else { SetControlText(string.Empty); } }
private void FillGrid(string name, BaseUtils.SortedListDoubleDuplicate <ISystem> csl) { DataGridViewColumn sortcolprev = dataGridViewNearest.SortedColumn != null ? dataGridViewNearest.SortedColumn : dataGridViewNearest.Columns[1]; SortOrder sortorderprev = dataGridViewNearest.SortedColumn != null ? dataGridViewNearest.SortOrder : SortOrder.Ascending; dataGridViewNearest.Rows.Clear(); if (csl != null && csl.Any()) { SetControlText(string.Format("From {0}".T(EDTx.UserControlStarDistance_From), name)); int maxdist = 0; foreach (KeyValuePair <double, ISystem> tvp in csl) { double dist = Math.Sqrt(tvp.Key); // distances are stored squared for speed, back to normal. maxdist = Math.Max(maxdist, (int)dist); if (tvp.Value.Name != name && (checkBoxCube.Checked || (dist >= textMinRadius.Value && dist <= textMaxRadius.Value))) { int visits = discoveryform.history.GetVisitsCount(tvp.Value.Name); object[] rowobj = { tvp.Value.Name, $"{dist:0.00}", $"{visits:n0}" }; int rowindex = dataGridViewNearest.Rows.Add(rowobj); dataGridViewNearest.Rows[rowindex].Tag = tvp.Value; } } if (csl.Count > maxitems / 2) // if we filled up at least half the list, we limit to max distance plus { lookup_limit = maxdist * 11 / 10; // lookup limit is % more than max dist, to allow for growth } else if (csl.Count > maxitems / 10) { lookup_limit = maxdist * 2; // else we did not get close to filling the list, so double the limit and try again } else { lookup_limit = 100; // got so few, lets reset } System.Diagnostics.Debug.WriteLine("Star distance Lookup " + name + " found " + csl.Count + " max was " + maxdist + " New limit " + lookup_limit); } else { SetControlText(string.Empty); } dataGridViewNearest.Sort(sortcolprev, (sortorderprev == SortOrder.Descending) ? ListSortDirection.Descending : ListSortDirection.Ascending); dataGridViewNearest.Columns[sortcolprev.Index].HeaderCell.SortGlyphDirection = sortorderprev; }