简体   繁体   English

C#查找需要多少个Datagrid行/列

[英]C# Finding how many Datagrid rows/columns are needed

I got an assignment where I have to read text from a file and extract numbers into a DataGrid , so my question is how to know how many rows or/and columns I need for the DataGrid to look nice, and to be filled with numbers. 我有一个作业,我必须从文件中读取文本并将数字提取到DataGrid ,所以我的问题是如何知道DataGrid看起来不错并需要填充多少行和/或列。

So if I have 9 numbers the grid should be something like 3x3 , or if I have 18 --> 6x3 etc. 因此,如果我有9个数字,则网格应该像3x3一样,或者如果我有18-> 6x3等。

The amount of numbers can be from 1 to 9999999 (a lot). 数字的数量可以从1到9999999(很多)。

I was thinking about doing something like: 我正在考虑做类似的事情:

int x, i, j;   //x-amount of numbers,i-rows,j-columns

while (i * j < a)
{
     if (a % 2 == 0)
       {
         i++;
         j++;
       }
}

And so on and on and on for as many different cases as I could think of, in the end all the grids would either be half empty or completely broken and unusable like 1x17. 依此类推,在不尽相同的情况下,最终所有的网格要么是半空的,要么是完全破碎的,无法使用,就像1x17。

  1. Check if the number is prime or not. 检查数字是否为素数。 It must not be a prime number. 它不能是素数。

  2. Check if that number is divisible by any number between 2 - 20. So, lets say number is 2378, we see that 2378 = 2*1189. 检查该数字是否可被2到20之间的任何整数整除。因此,假设数字为2378,我们看到2378 = 2 * 1189。 Generally, row count is always greater than columns. 通常,行数总是大于列。 As columns represent field names. 由于列代表字段名称。 So, you have 1189 rows and 2 columns. 因此,您有1189行和2列。 Start from 20 backwards, as we want maximum columns in your display. 从20向后开始,因为我们希望显示的列数最大。

    Now, suppose you have 8645, 8645 = 455 * 19, also 8645 = 1235 * 7. So, we choose 455 * 19 => 455 rows, 19 columns. 现在,假设您有8645、8645 = 455 * 19,还有8645 = 1235 *7。因此,我们选择455 * 19 => 455行19列。

  3. Now, you have to take care of screen resolution. 现在,您必须注意屏幕分辨率。 Thats a tricky part. 那是一个棘手的部分。 But anyhow 20 columns looks reasonable in any resolution. 但是无论如何,20列在任何分辨率下看起来都是合理的。 Use SystemParameters.FullPrimaryScreenWidth to aid you. 使用SystemParameters.FullPrimaryScreenWidth可以帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM