listbox 相关问题

一个图形用户界面元素,允许用户从列表中选择一个或多个项目。

列表框到 Excel 工作表

我这里有一个按人名过滤的列表框。当从组合框中选择名称时,列表框将正确填充。我想要实现的是当列表框显示时......

回答 1 投票 0

列表框拒绝更新/列表没有匹配的类型

简而言之,我想创建一个可更新的列表框,它会在从组合框中选择选项时更新 简而言之,我想创建一个可更新的列表框,它会在从组合框中选择选项时进行更新 <ListBox Background="Transparent" Width="Auto" Height="Auto" HorizontalAlignment="Right" ScrollViewer.CanContentScroll="true" ItemsSource="{Binding Lessons, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"> <ListBox.ItemTemplate> <DataTemplate> <WrapPanel> <TextBlock Text="{Binding LessonText, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}"> <StackPanel> </StackPanel> </TextBlock> <Image Source="{Binding LessonImage, UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" HorizontalAlignment="Center" Width="auto" MaxWidth="400"/> </WrapPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> 更改变量 Lesson 的值会触发一个操作,该操作会用元素填充对象列表 public class LessonData : BaseViewModel { public int _lessonID; public string _lessonText; public byte[] _lessonImage; public int LessonID { get { return _lessonID; } set { _lessonID = value; OnPropertyChanged(nameof(LessonID)); } } public string LessonText { get { return _lessonText; } set { _lessonText = value; OnPropertyChanged(nameof(LessonText)); } } public byte[] LessonImage { get { return _lessonImage; } set { _lessonImage = value; OnPropertyChanged(nameof(LessonImage)); } } } public List<LessonData> editedLessons = new List<LessonData>(); public List<LessonData> EditedLessons { get { return editedLessons; } set { editedLessons = value; OnPropertyChanged(nameof(EditedLessons)); } } public string Lesson { get { return _lesson; } set { _lesson = value; OnPropertyChanged(nameof(Lesson)); if (Lesson == "None") { EditedLessons.Clear(); IsLessonBeingEdited = false; } else { EditedLessons = lessonRepository.Obtain_Lesson_Content(Lesson); foreach (LessonData p in EditedLessons) { Console.WriteLine(p.LessonID, p.LessonText, p.LessonImage); } IsLessonBeingEdited = true; } } } 这是存储库中的函数 public List<LessonData> Obtain_Lesson_Content(string Lesson) { List<LessonData> lc = new List<LessonData>(); using (var connection = GetConnection()) using (var command = new SqlCommand()) { connection.Open(); command.Connection = connection; command.CommandText = "SELECT Id_Lesson_Content, Lesson_Text, Lesson_Image FROM [Lesson_Content] WHERE Id_Lesson_Title = (SELECT Id_Lesson FROM [Lesson_Title] WHERE Lesson_Title = @title)"; command.Parameters.Add("@title", SqlDbType.NVarChar).Value = Lesson; using (var reader = command.ExecuteReader()) { while (reader.Read()) { LessonData model = new LessonData(); model.LessonID = (int)reader["Id_Lesson_Content"]; model.LessonText = reader["Lesson_Text"].ToString(); if (reader["Lesson_Image"] != System.DBNull.Value) model.LessonImage = (byte[])reader["Lesson_Image"]; else model.LessonImage = null; lc.Add(model); } reader.NextResult(); } foreach (LessonData p in lc) { Console.WriteLine(p.LessonID, p.LessonText, p.LessonImage); } return lc; } } 然而,每次我触发该函数时,我都会遇到抛出的错误(在这种情况下,它正在加载两个对象,一个带有图像,一个没有图像): System.Windows.Data Error: 1 : Cannot create default converter to perform 'two-way' conversions between types 'System.Byte[]' and 'System.Windows.Media.ImageSource'. Consider using Converter property of Binding. BindingExpression:Path=LessonImage; DataItem='LessonData' (HashCode=2419756); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='System.Byte[]' BindingExpression:Path=LessonImage; DataItem='LessonData' (HashCode=2419756); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource') System.Windows.Data Error: 1 : Cannot create default converter to perform 'two-way' conversions between types 'System.Byte[]' and 'System.Windows.Media.ImageSource'. Consider using Converter property of Binding. BindingExpression:Path=LessonImage; DataItem='LessonData' (HashCode=10026414); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource') 但对我来说,最奇怪的部分是尝试在控制台中写入所有列表对象会引发这三个错误: 无法从 int 转换为 char[], 从字符串到整数 从 byte[] 到 int foreach (LessonData p in lc) { Console.WriteLine(p.LessonID, p.LessonText, p.LessonImage); } 比如,为什么会发生这种情况?我查看了其他相同/相似的函数,它们以相同的方式工作,并且它们都没有抛出此类编译错误。最重要的是,当我通过将LessonID放在最后来更改对象元素的顺序时,它不会显示错误(但是显示的唯一项目是LessonText)。 无论是什么原因,我相信它隐藏在阅读列表的错误背后。 错误消息的来源是绑定表达式 Source="{Binding LessonImage, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 虽然存在从 string、Uri 和 byte[] 到 ImageSource(Source 属性的类型)的内置自动类型转换,但不会自动转换回这些类型(字符串除外) . 除此之外, Source 属性的双向绑定是没有意义的,因为 Image 元素本身永远不会更改该属性。这同样适用于 TextBlock 元素的 Text 属性绑定。 解决方案是使用 OneWay Binding,其中设置 UpdateSourceTrigger 也是毫无意义的,因为它只影响 TwoWay 和 OneWayToSource Binding。 Source="{Binding LessonImage}"

回答 1 投票 0

如何仅使用工作表中的某些列填充列表框?

我有一个使用以下代码填充的列表框: 私有子用户form_initialize() 昏暗的工作表 调暗 Rng As 范围 变暗 LRow 一样长 变暗 Myarray 作为变体 设置 ws = ThisWorkbook.Sheets(Mark1.

回答 1 投票 0

如何在列表框中显示字典

我正在尝试将字典中的键/值对显示到列表框。 核心价值 一个 10 乙20 碳30 我想以以下格式将它们显示在列表框中 甲(10) 乙(20) C(30) 使用以下...

回答 4 投票 0

从 Excel 工作表到列表框显示与其他列的唯一值

我这里有数据,我想获取 C 列 = 项目 ID 的唯一值。 日期 ||项目编号 ||实施领域||开始时间 ||结束时间 ||地位 2023 年 8 月 28 日 || 1145544 ||

回答 1 投票 0

单击启用宏的按钮时列表框不显示条目

我有一个列表框,当从 Excel 工作表中单击按钮时,应该在初始化中显示条目。 该按钮正在调用一个模块来显示表单。 模块代码: 选项显式 子翔...

回答 1 投票 0

使用一个滚动条滚动多个列表框而不使用类

我想在 Tkinter 中使用单个(垂直)滚动条同时(同步)滚动多个列表框。 问题是 Stack Overflo 上的所有解决方案......

回答 2 投票 0

同时滚动多个 Tkinter 列表框

我有多个 Tkinter 列表框,我使用单个滚动条将它们一起滚动,但我还希望它们一起滚动以在任何列表框上进行鼠标滚轮活动。 怎么办...

回答 5 投票 0

无法编译64位CXTipListBox

我正在尝试从此处的类中获取 CXTipListBox: https://www.codeproject.com/Articles/4438/XTipComboBox-Display-tooltips-for-combobox 将其用于对话框上的 CListBox 控件。 它...

回答 1 投票 0

Excel VBA 表单在列表框中显示带有时间计算的唯一条目

我想请您帮助解决我的以下问题。我这里有两种不同的形式。用于保存条目的表格 1。为了保存条目,我已经有了代码。它已经开始工作了。表格 2 是用来显示...

回答 1 投票 0

在用户表单初始化期间设置列表框(在 VBA 中)的列宽时,Excel 崩溃

问题:每次我尝试加载用户表单(“MS Excel 已停止响应”)时,特别是在设置列表框的列宽时,我的 MS Excel 都会间歇性崩溃。 背景:使用

回答 2 投票 0

GUI 中的 Python Tkinter 列表框文本编辑

有没有办法编辑列表框项目而不是删除它? 我正在使用带有列表框的 tkinter GUI。现在我的列表框可以包含例如 10 个项目。如果我想更改一项的文本...

回答 2 投票 0

无法使列表框选择显示在文本框中

列表框选择未按预期显示在相应的文本框中。尽管代码逻辑将列表框中的选定值连接并显示到文本框中,但

回答 1 投票 0

使一组 WPF 扩展器专门“扩展”,即一次仅扩展一个

我有一个包含一组“Expander”项目的列表框,我想做的是使每个项目的 IsExpanded 属性都是独占的。例如,如果列表框中有 10 个 Expander,...

回答 3 投票 0

Excel 列表框仅显示当前日期输入的条目

我想请求您帮助仅显示当前日期的列表框条目。我这里有一个示例,其中包含先前日期输入的条目以及今天日期的条目。每次我...

回答 1 投票 0

Excel VBA:根据用户窗体上多选列表框中的选择更改表值

我有一个工作簿,我正在尝试使用用户窗体来控制工作表的可见性。 表 (tblDefaultValues) 包含每个工作表的数据。该表包括包含默认值的列...

回答 1 投票 0

ListBox 数据源自动重置不适用于 C++/CLI 中的列表

我有一个 C++/CLI 中的 WinForm 项目。我使用列表作为列表框的数据源。我将 myList 定义为 mainForm(void) 中列表框的数据源。在用户界面中,当用户单击按钮1时,程序添加文本框->t...

回答 1 投票 0

当 DataTemplate 为 Button 时,ListBox 项返回字符串

我正在创建一个 WP 8.1 Silverlight 应用程序。 我有一个字符串名称的 ObservableCollection,它设置为 ListBox 的 ItemsSource。这是列表框中按钮的名称。然后我想...

回答 1 投票 0

选择 Tkinter 列表框中的所有项目后如何显示消息框?

我编写了一个 GUI 调用脚本,其中每一行都是列表框中的一个项目。我想要一个消息框来告诉用户列表框中的所有项目都已完成。如果可能的话请提供帮助。 如果 int(列表...

回答 1 投票 0

在Python中如何声明动态数组

我想声明一个数组,并且无论列表框中存在的组名称如何,都应该删除列表框中存在的所有项目。任何人都可以帮助我用 Python 编码吗?我使用的是 WINXP 操作系统 &...

回答 5 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.