簡體   English   中英

如何擺脫我的gridview WPF中的空表?

[英]How do I get rid of the empty table in my gridview WPF?

因此,我最近在WPF中為數據庫應用程序創建了GridView。 它保存了我的網站用戶的用戶名和密碼,並且運行良好。唯一的問題是,它在右側添加了空列,但我沒有理由。 我做錯了什么以及如何正確做? 我無法單擊右邊的列,就像它只是null。

XML格式

<DataGrid HeadersVisibility="Column" CanUserAddRows="False" BorderBrush="Black" Name="dgAccounts" Foreground="Black" Margin="10,103,405,10">
                <DataGrid.Columns>
                </DataGrid.Columns>
            </DataGrid>

C#

private void RetrieveUserData()
        {
            string line;
            using (WebClient wc = new WebClient())
            {
                string accs = wc.DownloadString(Clipboard.GetText());

                using (StringReader sr = new StringReader(accs))
                {
                    while ((line = sr.ReadLine()) != null)
                    {
                        newAccounts.Add(new Accounts { Username = theUsername, Password = thePassword });
                    }
                }
            }
            dgAccounts.ItemsSource = newAccounts;
        }

在這里您可以看到問題的模樣

假設您的DataGrid為固定大小,則空列將作為其他列的結果,僅使用它們所需的空間。

嘗試設置每列的寬度,我建議使用Width="*"來確保使用整個網格,並且每列使用相等的空間。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM