How to add a new item into ObjectListView?

I tried the demo code in demo project but I can't add new item successfully. It just add new new NULL group and NULL item. Please give me an simple example code to add new item (text and image).

Thank you!

Oh sorry! I forgot it. This is the first time I participate in this site. I use C#. And the code is:

objectListView1.AddObject(new string [] {"Hello","dfdsF" });


OLVListItem item = new OLVListItem(new string [] {"Hello","dfdsF" });

It's so different form ListView and EXListView which I can define a text or a image when creating new item. But in ObjectListView, I don't understand OBJECT?

I get ObjectListView anh it's demo code form here http://nchc.dl.sourceforge.net/project/objectlistview/objectlistview/v2.5/ObjectListViewFull-2.5.0.zip


I will show you what to do to add items. Try to create a class, then make getters and setters for the properties you want to show on your ObjectListView.

SetObjects method takes a List<T>:

public Form1()

Now this is my class, I called it haha, I've two properties in it (Name and Detail):

class haha
    string name;
    string detail;
    public haha(string name , string detail)
        this.name = name;
        this.detail = detail;

    public string Name
        get { return name; }
        set { name = value; }
    public string Detail
        get { return detail; }
        set { detail = value; }

    static internal List<haha> GET()
        haha item = new haha("zeko", "dunno");
        haha xx = new haha("sheshe", "dunno");
        haha ww = new haha("murhaf", "dunno");
        haha qq = new haha("soz", "dunno");
        haha ee = new haha("HELLO", "dunno");
        List<haha> x = new List<haha>();
        return x;


  • change ShowGroups in ObjectListView to false
  • then add the columns that you want; I've added two columns, one for Name and one for Detail
  • and as in the picture when you add a column, see the AspectName and write exactly the same name of its property that you want to show from your class

enter image description here

Here's the result:

enter image description here

If you want to use AddObject(), which takes an object, I'd write this:

private void button1_Click(object sender, EventArgs e)
    haha newObject = new haha("memo","zezo");

Happy coding :)

The best thing is to use an entity class. Then make a list of items and add this list to your ObjectListView.


But before you do that, you have to setup the columns in your designer. Just add a column, and in the field AspectName enter the exact name of the attribute of your entity item.

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

  • 即使将焦点放在另一个控件上,如何更改listview所选行的背景色?(How to change listview selected row backcolor even when focus on another control?)
    问题 我有一个使用条形码扫描仪作为输入设备的程序,这意味着我需要将重点放在文本框上。 该程序具有一个listview控件,当扫描特定条形码时,我将以编程方式选择其中一项。 我通过以下方式设置行的背景色: listviewitem.BackColor = Color.LightSteelBlue; 我尝试过的事情: listview.HideSelection设置为false 设置颜色后调用listview.Focus() listviewitem.Focused设置为true 呼叫listview.Invalidate 呼叫listview.Update() 调用listview.Refresh() 上面的不同组合 我还在计时器中进行了上述组合,因此它们在不同的线程上被调用,但仍然没有成功。 有任何想法吗? 更多信息: 这里的关键是控制焦点。 选择其中一项时, listview控件没有焦点。 我通过执行以下操作选择一项: listView1.Items[index].Selected = true; 焦点始终在文本框中。 该计算机没有键盘或鼠标,只有条形码读取器。 我有以下代码可以将重点放在文本框上: private void txtBarcode_Leave(object sender, EventArgs e) { this.txtBarcode.Focus(); }
  • 使用自定义(对象)适配器过滤ListView(Filtering ListView with custom (object) adapter)
    问题 我正在尝试对使用自定义对象适配器的ListView进行过滤,但是找不到任何有用的示例。 包含的代码非常简化,因此请记住,我不能使用常规的ArrayAdapter。 我在ListView上方有一个EditText,当用户在EditText小部件中输入文本时,我想用EditText中编写的文本过滤ListView。 我们欢迎所有的建议! 这是活动类的摘录: public class management_objects extends Activity { private static List<User> UserList; private EfficientAdapter adapter = null; private ListView objectListView = null; private EditText SearchText = null; private static class EfficientAdapter extends BaseAdapter implements Filterable{ private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int
  • The relationship between the two objects cannot be defined because they are attached to different ObjectContext objects
    I have 2 tables in SQL. One is called Training and one is called Consultants. Training is couple of fields like ID, Place, Time, Date and it also has ConsultantName which is foreign key and is connected with Consultants having ConsultantName, ConsultantFirstName etc. During save of Training i save the training first and then pass the Training value as varTraining. I tried to attatch it to context as per some suggestions I found on stack but it doesn't seem to work: Training Training = context.Trainings.First(p => p.TrainingID == varTraining.TrainingID); context.Trainings.Attach(Training)
  • Filtering ListView with custom (object) adapter
    I'm trying to implement filtering of a ListView which is uses a custom object adapter, but I can't find any useful samples. The included code is very simplified, so no- keep in mind I can't use an regular ArrayAdapter. I have a EditText above the ListView, and when the user enters text in the EditText widget I would like to filter the ListView by the text written in the EditText. Any suggestions would be much appreciated! Here is the snippet from the activity class: public class management_objects extends Activity { private static List<User> UserList; private EfficientAdapter adapter = null
  • 在WinForms中将按钮添加到Listview中(Adding button into a Listview in WinForms)
    问题 有没有一种方法可以将按钮控件添加到WinForms应用程序中ListView内部的单元格中? 回答1 这是可以重用的类ListViewExtender的代码。 它不是ListView的派生类,基本上,您只是声明特定列显示为按钮而不是文本。 按钮的文本是子项的文本。 它允许没有问题的大型列表视图,不使用p / invoke,并且还可以与水平滚动条一起使用(此处提出的一些答案的代码在很多项目中没有或相当慢)。 注意,它要求扩展ListView的FullRowSelect设置为true ,视图类型设置为Details 。 这是使用它的示例代码: namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); // you need to add a listView named listView1 with the designer listView1.FullRowSelect = true; ListViewExtender extender = new ListViewExtender(listView1); // extend 2nd column ListViewButtonColumn buttonAction
  • 在ListView的网格中显示128x128像素或更大的缩略图图标(Displaying thumbnail icons 128x128 pixels or larger in a grid in ListView)
    问题 原始问题(请参阅下面的更新) 我有一个WinForms程序,它需要一个带有大图标(实际上是128x128或更大的缩略图)的体面的可滚动图标控件,可以单击该图标来突出显示或双击来执行某些操作。 最好将空间浪费最小化(每个图标下方可能需要短文件名标题;如果文件名太长,我可以添加省略号)。 (来源:updike.org) 我尝试将ListView与LargeIcon(默认为.View)一起使用,结果令人失望: (来源:updike.org) 也许我没有正确填充控件? 代码: ImageList ilist = new ImageList(); this.listView.LargeImageList = ilist; int i = 0; foreach (GradorCacheFile gcf in gc.files) { Bitmap b = gcf.image128; ilist.Images.Add(b); ListViewItem lvi = new ListViewItem("text"); lvi.ImageIndex = i; this.listView.Items.Add(lvi); i++; } 我需要带有很少空白空间的大图标,而不需要带有令人尴尬的小图标的大空白空间。 是否有我需要的.NET控件? 有没有喜欢的第三方控件可以做到这一点? 如果不是
  • ListView onScroll事件(ListView onScroll event)
    问题 我正在编写一个简单的C#应用​​程序,并且需要Listview上的onScroll事件。 所以我创建了ListviewEx类,它继承了原始的ListView。 我发现了如何从WinAPI中检测滚动消息,并修改了WndProc方法。 现在我有了这个WndProc: protected override void WndProc(ref Message m) { base.WndProc(ref m); if (m.Msg == WM_VSCROLL) { onScroll(this, new EventArgs()); } } 但是问题是,我不知道如何检测有关滚动的信息。 此数据应在WParam中,但在C#中没有像C ++中那样的LOWORD宏,我需要切换以检测SB_ BOTTOM,SB_ ENDSCROLL,SB_PAGEUP等参数。 有什么办法可以替换C#中的LOWORD宏吗? 或其他方式如何检测有关滚动的必要参数? 回答1 您可以按以下方式定义WParam常量: private const int WM_HSCROLL = 0x114; private const int WM_VSCROLL = 0x115; private const int SB_HORZ = 0; private const int SB_VERT = 1; private const int
  • How to highlight selected item in RecyclerView
    I have used RecyclerView for showing thumbnails in my Image Editing app.Each item of its comprises of a ImageView(thumbnail) and a textView.In my application I want to highlight only current selected thumbnail when clicked.Gone through all the related posts on SO but couldn't find any better solution. My Adapter Class public class FiltersAdapter extends RecyclerView.Adapter<FiltersAdapter.ViewHolder> { private Context mContext; private List<Type> mDataSet; private Uri selectedPhoto; public enum Type { Original, Grayscale, Sepia, Contrast, Invert, Pixel, Sketch, Swirl, Brightness, Vignette }
  • 如何使用oledb将记录插入访问表中?(How to insert a record into a access table using oledb?)
    问题 我在ms access中有这个Items表 Items(Table) Item_Id(autonumber) Item_Name(text) Item_Price(currency) 我正在尝试使用此代码插入一条记录。 OleDbConnection myCon = new OleDbConnection(ConfigurationManager.ConnectionStrings["DbConn"].ToString()); OleDbCommand cmd = new OleDbCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "insert into Items ([Item_Name],[Item_Price]) values ('" + itemNameTBox.Text + "','" + Convert.ToDouble(itemPriceTBox.Text) + "')"; cmd.Connection = myCon; myCon.Open(); cmd.ExecuteNonQuery(); System.Windows.Forms.MessageBox.Show("An Item has been successfully added", "Caption"
  • 在PHP中合并XML文件(Merge XML files in PHP)
    问题 我有2个文件1.xml和2.xml都具有相似的结构,我想拥有一个。 我尝试了许多解决方案,但只有错误-坦白地说,我不知道这些脚本是如何工作的。 1.xml : <res> <items total="180"> <item> <id>1</id> <title>Title 1</title> <author>Author 1</author> </item> ... </items> </res> 2.xml : <res> <items total="123"> <item> <id>190</id> <title>Title 190</title> <author>Author 190</author> </item> ... </items> </res> 我想用以下结构创建一个新文件merged.xml <res> <items total="303"> <item> <id>1</id> <title>Title 1</title> <author>Author 1</author> </item> ... //items from 1.xml <item> <id>190</id> <title>Title 190</title> <author>Author 190</author> </item> ... //items from 2.xml </items>
  • Merge XML files in PHP
    I have 2 files 1.xml and 2.xml both having similar structure and I would like to have one. I tried many solutions but I had errors only - frankly speaking I have no idea how those scripts worked. 1.xml: <res> <items total="180"> <item> <id>1</id> <title>Title 1</title> <author>Author 1</author> </item> ... </items> </res> 2.xml: <res> <items total="123"> <item> <id>190</id> <title>Title 190</title> <author>Author 190</author> </item> ... </items> </res> I would like to create a new file merged.xml with the following structure <res> <items total="303"> <item> <id>1</id> <title>Title 1</title>
  • 如何使用Powershell将CSV导出到Excel(How to export a CSV to Excel using Powershell)
    问题 我正在尝试使用Powershell将完整的CSV导出到Excel。 我停留在使用静态列名称的地方。 但是,如果我的CSV具有通用的未知标头名称,则此方法不起作用。 重现步骤 打开您的PowerShell ISE,然后复制并粘贴以下独立代码。 用F5运行 “ C:\ Windows \ system32 \ WindowsPowerShell \ v1.0 \ powershell_ise.exe” Get-Process | Export-Csv -Path $env:temp\process.csv -NoTypeInformation $processes = Import-Csv -Path $env:temp\process.csv $Excel = New-Object -ComObject excel.application $workbook = $Excel.workbooks.add() $i = 1 foreach($process in $processes) { $excel.cells.item($i,1) = $process.name $excel.cells.item($i,2) = $process.vm $i++ } Remove-Item $env:temp\process.csv $Excel.visible = $true 它能做什么
  • 将数组划分为子序列数组(Divide array into an array of subsequence array)
    问题 我有一个字节数组: byte[] bytes; // many elements 我需要将其划分为X元素的字节数组的子序列。 例如,x = 4。 如果bytes.Length不乘以X,则将0添加到最后一个子序列数组,因此所有子序列的Length必须为X。 Linq可用。 PS:我的尝试 static void Main(string[] args) { List<byte> bytes = new List<byte>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; int c = bytes.Count / 4; for (int i = 0; i <= c; i+=4) { int diff = bytes.Count - 4; if (diff < 0) { } else { List<byte> b = bytes.GetRange(i, 4); } } Console.ReadKey(); } 回答1 这很可爱: static class ChunkExtension { public static IEnumerable<T[]> Chunkify<T>( this IEnumerable<T> source, int size) { if (source == null) throw new
  • 具有多线程或任务的进程队列(Process queue with multithreading or tasks)
    问题 我有一个电话消息应用程序,其中要处理的消息很多,由于电话端口有限,因此消息将按先进先出的顺序处理。 每个消息都有一个标志“ Acknowledge”,该标志指示处理的是哪个。 当然,它被初始化为false。 我想将所有消息放入队列,然后使用多个线程或任务处理它们。 public class MessageQueue { public Queue MessageWorkItem { get; set; } public Messages Message { get; set; } public MessageQueue() { MessageWorkItem = new Queue(); Message = new Messages(); } public void GetMessageMetaData() { try { // It is just a test, add only one item into the queue Message.MessageID = Guid.NewGuid(); Message.NumberToCall = "1111111111"; Message.FacilityID = "3333"; Message.NumberToDial = "2222222222"; Message.CountryCode = "1"; Message
  • C#SQL Server-将列表传递到存储过程(C# SQL Server - Passing a list to a stored procedure)
    问题 我正在从我的C#代码中调用SQL Server存储过程: using (SqlConnection conn = new SqlConnection(connstring)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("InsertQuerySPROC", conn)) { cmd.CommandType = CommandType.StoredProcedure; var STableParameter = cmd.Parameters.AddWithValue("@QueryTable", QueryTable); var NDistanceParameter = cmd.Parameters.AddWithValue("@NDistanceThreshold", NDistanceThreshold); var RDistanceParameter = cmd.Parameters.AddWithValue(@"RDistanceThreshold", RDistanceThreshold); STableParameter .SqlDbType = SqlDbType.Structured; NDistanceParameter.SqlDbType = SqlDbType.Int
  • How to add/insert an item into an ObservableArray at a certain position with Knockout.js
    All the knockout examples I have found seem to add a new item to the end of an ObservableArray using something like: viewModel.SomeItems.push(someNewItem); This of course places the item at the end of the array. How to I add an item to the ObservableArray at a certain position? eg. something like: viewModel.SomeItems.push(someNewItem, indexToInsertItAt);
  • 如何将JSON转换为XML或将XML转换为JSON?(How to convert JSON to XML or XML to JSON?)
    问题 我开始使用Json.NET将JSON格式的字符串转换为对象,反之亦然。 我不确定在Json.NET框架中是否可以将JSON中的字符串转换为XML格式,反之亦然? 回答1 是的。 使用JsonConvert类,其中包含用于此精确目的的辅助方法: // To convert an XML node contained in string xml into a JSON string XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); string jsonText = JsonConvert.SerializeXmlNode(doc); // To convert JSON text contained in string json into an XML node XmlDocument doc = JsonConvert.DeserializeXmlNode(json); 此处的文档:使用Json.NET在JSON和XML之间进行转换 回答2 是的,您可以做到(我可以做到),但是在转换时请注意一些悖论,并进行适当的处​​理。 您无法自动符合所有接口的可能性,并且控制转换的内置支持有限-许多JSON结构和值无法自动以两种方式转换。 请记住,我在Newtonsoft JSON库和MS XML库中使用默认设置
  • 如何将字符串拆分为多个值?(How do i split a String into multiple values?)
    问题 您如何分割字符串? 可以说我有一个字符串“狗,猫,老鼠,鸟” 我的实际目标是将这些动物中的每一个插入到listBox中,以便它们成为列表框中的项目。 但是我想如果我知道如何分割字符串,我就会知道如何插入这些项目。 还是有人知道更好的方法吗? 我正在使用asp c# 回答1 string[] tokens = text.Split(','); for (int i = 0; i < tokens.Length; i++) { yourListBox.Add(new ListItem(token[i], token[i])); } 回答2 您是否尝试过String.Split? 如果要使“ a,b,c”以{“ a”,“ b”,“ c”}结尾但要使“ ab,c”以{” ab结尾,则可能需要一些后期处理以删除空格“, “C”}。 例如: private readonly char[] Delimiters = new char[]{','}; private static string[] SplitAndTrim(string input) { string[] tokens = input.Split(Delimiters, StringSplitOptions.RemoveEmptyEntries); // Remove leading and trailing
  • Add item into List from View and pass to Controller in MVC5
    I have a form like this: JS Code: $(document).ready(function() { $("#add-more").click(function() { selectedColor = $("#select-color option:selected").val(); if (selectedColor == '') return; var color = ' < div class = "form-group" > < label class = "col-md-2 control-label" > Color: < /label> < div class = "col-md-5" > < label class = "control-label" > ' + selectedColor + ' < /label></div > < /div> '; var sizeAndQuantity = ' < div class = "form-group" > < label class = "col-md-2 control-label" > Size and Quantity: < /label> < div class = "col-md-2" > < label class = "control-label" > S < /label
  • 如何将项目添加到numpy数组(How to add items into a numpy array)
    问题 我需要完成以下任务: 从: a = array([[1,3,4],[1,2,3]...[1,2,1]]) (向每行添加一个元素)到: a = array([[1,3,4,x],[1,2,3,x]...[1,2,1,x]]) 我已经尝试做类似a [n] = array([1,3,4,x])的事情 但是numpy抱怨形状不匹配。 我尝试遍历a并将元素x附加到每个项目,但是更改未反映出来。 关于如何实现此目标的任何想法? 回答1 对于有python经验的人来说,将数据追加到现有数组是很自然的事情。 但是,如果您发现自己定期附加到大型数组,则会很快发现NumPy不能像python list那样轻松或有效地执行此操作。 您会发现,每个“追加”操作都需要重新分配阵列内存,并且短期内需要增加一倍的内存。 因此,解决该问题的更一般的方法是尝试将数组分配为与算法的最终输出一样大。 然后,对该阵列的子集(切片)执行所有操作。 理想情况下,应最小化阵列的创建和破坏。 就是说,这通常是不可避免的,执行此操作的功能是: 对于二维数组: np.hstack np.vstack np.column_stack np.row_stack 对于3-D数组(上面加上): 例如dstack 对于ND阵列: np.concatenate 回答2 import numpy as np a = np.array([[1