简体   繁体   English

在 c# Xamarin 上显示来自 db 的 ListView 数据时,有没有办法从屏幕而不是字符串中删除 System.Collection.Generic 消息

[英]Is there a way to remove System.Collection.Generic message from screen instead of string when display ListView data from db on c# Xamarin

I want when the user clicks on my first listView to show a second listview with different data from database, but I see this Message: "System.Collections.Generic.List'1[System..."我希望当用户单击我的第一个 listView 以显示具有来自数据库的不同数据的第二个列表视图时,但我看到此消息: "System.Collections.Generic.List'1[System..."

When I use debugger everything is fine.. I see the data from the date base..当我使用调试器时一切都很好..我看到了来自日期库的数据..

My second listview look like this:我的第二个列表视图如下所示:

           <StackLayout>
              <ListView x:Name="MeteoView"
                        ItemsSource="{Binding Forecast}"
                        HeightRequest="100"
                        IsVisible="false">
                <ListView.ItemTemplate>
                  <DataTemplate>
                    <TextCell 
                        Text="{Binding DisplayRun}" />
                  </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>

My c# code to connect with db, execute the procedure and display the data look like this:我的 C# 代码与 db 连接,执行程序并显示数据如下所示:

 public class ForecastData
    {
        public string DisplayRun { get; set; }
    }

    ObservableCollection<ForecastData> MeteoData = new ObservableCollection<ForecastData>();
    public ObservableCollection<ForecastData> Forecast { get { return MeteoData; } }

    void listView_ItemSelected(System.Object sender, Xamarin.Forms.SelectedItemChangedEventArgs e)
    {    

        string str = ((Contacts)listView.SelectedItem).Place;

        string substr = str.Substring(str.Length - 5);

        searchBar.Placeholder = str;

        server = "ip-to-db";
        database = "db-name";
        uid = "user";
        password = "pass";
        string connectionString;
        connectionString = "SERVER=" + server + ";" + "DATABASE=" +
        database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
        connection = new MySqlConnection(connectionString);


        List<string> Run = new List<string>();
        
        
        try
        {
            connection.Open();
            var cmd = new MySqlCommand();
            cmd.Connection = connection;
            MySqlCommand command = new MySqlCommand($"CALL `get_all_data`({substr})", connection);

            MeteoView.IsVisible = true;
            MeteoView.ItemsSource = MeteoData;

            using (MySqlDataReader reader = command.ExecuteReader())
            {
                while (reader.Read())
                {

                    Run.Add(reader[0].ToString()); 

                    MeteoData.Add(new ForecastData { DisplayRun = $"{Run}" });
                }
            }
            connection.Close();
        }

        catch (Exception ex)
        {
            LabelSQL.Text = (ex.ToString());
        }       
    }

So on my display emulator I see this one in the listView:所以在我的显示模拟器上,我在 listView 中看到了这个:

listView列表显示

Debugger调试器

this is essentially the same problem you asked about earlier today.这与您今天早些时候问过的问题基本相同。 By default ToString will return the name of the class.默认情况下ToString将返回类的名称。 You are setting DisplayRun to the contents of a List<string>您正在将DisplayRun设置为List<string>

List<string> Run = new List<string>();

Run.Add(reader[0].ToString()); 
MeteoData.Add(new ForecastData { DisplayRun = $"{Run}" });

which is basically the same as这基本上与

DisplayRun = Run.ToString();

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

相关问题 无法通过linq C#将类型system.collection.generic IEnumerable隐式转换为组中的模型 - cannot implicitly convert type system.collection.generic IEnumerable to models in group by linq c# CoreCLR支持System.Collection.Generic类型吗? - Is CoreCLR support System.Collection.Generic types? 显示 output 从 DB 查询的数据,但显示如下: (System.Collections.Generic.List`1[System.String]) - Display output data queried from DB but the following is displayed: (System.Collections.Generic.List`1[System.String]) 有没有一种简单的方法可以从 C# 中的 MongoDB 集合中删除所有数据? - Is there an easy way to remove all data from MongoDB collection in C#? 在C#中从DB在列表框中显示数据的最佳方法 - Best way to display data in a listbox from DB in C# 用于C#的C库,用于从操作系统队列中删除消息 - C library for C# to remove message from operating system queue 将数据从SQLite获取到ArrayAdapter / ListView-Android C#Xamarin - Get Data from SQLite into ArrayAdapter / ListView - Android C# Xamarin 从TXT文件Android C#Xamarin中删除行/字符串 - Remove line / string from TXT file Android c# Xamarin 命名空间错误 - &gt;使用com.demo并使用System.Collection.Generic - Namespace Error -> using com.demo & using System.Collection.Generic 如何在WPF C#中将数据从数据库显示到ListView - How to display data from database to ListView in WPF C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM