DataGridView控件就能直接编辑编辑数据啊,不过不知道是否符合你的需求
给一个简单的双击可编辑ListView的代码供你参考(我做了一点点修改,可以根据你自己的需要再修改):
ListViewExcs类文件,继承自ListView
using System;
using SystemDrawing;
using SystemWindowsForms;
namespace WinBaidu
{
//msg=0x115 (WM_VSCROLL)
//msg=0x114 (WM_HSCROLL)
/// <summary>
/// CListView 的摘要说明。
/// </summary>
public class ListViewEx : ListView
{
private TextBox m_tb;
public ListViewEx()
{
m_tb = new TextBox();
m_tbMultiline = true;
m_tbVisible = false;
thisGridLines = true;
//thisCheckBoxes = false;
thisFullRowSelect = true;
thisControlsAdd(m_tb);
}
private void EditItem(ListViewItemListViewSubItem subItem)
{
EditItem(subItem, subItemBounds);
}
private void EditItem(ListViewItemListViewSubItem subItem, Rectangle rt)
{
if (thisSelectedItemsCount <= 0)
{
return;
}
Rectangle _rect = rt;
m_tbBounds = _rect;
m_tbBringToFront();
m_tbFont = subItemFont;
m_tbText = subItemText;
m_tbLeave += new EventHandler(tb_Leave);
m_tbTextChanged += new EventHandler(m_tb_TextChanged);
m_tbVisible = true;
m_tbTag = subItem;
m_tbSelect();
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (eKeyCode == KeysF2)
{
if (thisSelectedItemsCount > 0)
{
//thisSelectedItems[0]BeginEdit();
ListViewItem lvi = thisSelectedItems[0];
EditItem(lviSubItems[0], new Rectangle(lviBoundsLeft, lviBoundsTop, thisColumns[0]Width, lviBoundsHeight - 2));
}
}
baseOnKeyDown(e);
}
protected override void OnSelectedIndexChanged(EventArgs e)
{
thism_tbVisible = false;
baseOnSelectedIndexChanged(e);
}
protected override void OnDoubleClick(EventArgs e)
{
Point tmpPoint = thisPointToClient(CursorPosition);
ListViewItemListViewSubItem subitem = thisHitTest(tmpPoint)SubItem;
ListViewItem item = thisHitTest(tmpPoint)Item;
if (subitem != null)
{
if (itemSubItems[0]Equals(subitem))
{
EditItem(subitem, new Rectangle(itemBoundsLeft, itemBoundsTop, thisColumns[0]Width, itemBoundsHeight));
}
else
{
EditItem(subitem);
}
}
baseOnDoubleClick(e);
}
protected override void WndProc(ref Message m)
{
if (mMsg == 0x115 || mMsg == 0x114)
{
thism_tbVisible = false;
}
baseWndProc(ref m);
}
private void tb_Leave(object sender, EventArgs e)
{
m_tbTextChanged -= new EventHandler(m_tb_TextChanged);
(sender as TextBox)Visible = false;
}
private void m_tb_TextChanged(object sender, EventArgs e)
{
if ((sender as TextBox)Tag is ListViewItemListViewSubItem)
{
(thism_tbTag as ListViewItemListViewSubItem)Text = thism_tbText;
}
}
}
}
Form1cs文件
using System;
using SystemWindowsForms;
namespace WinBaidu
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
AddData();
}
public void AddData()
{
listViewEx1View = ViewDetails;
thislistViewEx1ColumnsAdd("姓名", 60, HorizontalAlignmentLeft);
thislistViewEx1ColumnsAdd("性别", 60, HorizontalAlignmentLeft);
thislistViewEx1ColumnsAdd("年龄", 60, HorizontalAlignmentLeft);
thislistViewEx1ColumnsAdd("公司", 60, HorizontalAlignmentLeft);
thislistViewEx1ItemsAdd(new ListViewItem(new String[] { "李雷", "男", "21", "GANA" }));
thislistViewEx1ItemsAdd(new ListViewItem(new String[] { "李雷", "男", "22", "GANA" }));
thislistViewEx1ItemsAdd(new ListViewItem(new String[] { "李雷", "男", "23", "GANA" }));
thislistViewEx1ItemsAdd(new ListViewItem(new String[] { "李雷", "男", "24", "GANA" }));
}
}
}
Form1Designercs文件
namespace WinBaidu
{
partial class Form1
{
/// <summary>
/// Required designer variable
/// </summary>
private SystemComponentModelIContainer components = null;
/// <summary>
/// Clean up any resources being used
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
componentsDispose();
}
baseDispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor
/// </summary>
private void InitializeComponent()
{
thislistViewEx1 = new WinBaiduListViewEx();
thisSuspendLayout();
//
// listViewEx1
//
thislistViewEx1Font = new SystemDrawingFont("PMingLiU", 12F, SystemDrawingFontStyleRegular, SystemDrawingGraphicsUnitPoint, ((byte)(136)));
thislistViewEx1FullRowSelect = true;
thislistViewEx1GridLines = true;
thislistViewEx1Location = new SystemDrawingPoint(13, 26);
thislistViewEx1Name = "listViewEx1";
thislistViewEx1Size = new SystemDrawingSize(549, 358);
thislistViewEx1TabIndex = 0;
thislistViewEx1UseCompatibleStateImageBehavior = false;
//
// Form2
//
thisAutoScaleDimensions = new SystemDrawingSizeF(6F, 12F);
thisAutoScaleMode = SystemWindowsFormsAutoScaleModeFont;
thisClientSize = new SystemDrawingSize(574, 405);
thisControlsAdd(thislistViewEx1);
thisName = "Form2";
thisText = "Form2";
thisResumeLayout(false);
}
#endregion
private ListViewEx listViewEx1;
}
}
今天在做一个功能:在初始化ListView时,把第一行背景置为**,同时保存第一行对象,用于在点击其他行时将该行重新置为白色。
if(position==0){
convertViewsetBackgroundColor(ColorYELLOW);
lastconvertView=convertView;
}
结果运行时发现第一行的颜色一直会是**而无法改变。调试了之后发现getView中 if(position==0) 居然会多次进入,最终导致的结果便是我最后一次取得的lastconvertView并非listview上面的第一行。网上查了之后发现原因是因为未固定listview的高度导致的,但是root cause却找不到说明。于是去翻阅了源码+大量调试,大概推算出了原因,在此记录。
首先是说明下ListView的显示机制,listview的机制是这样子的:
假如你有1000条数据,但是屏幕只能显示10条,那么当你第一次加载显示的时候,会先创建10个View,1-10,当你拖动Listview,使1隐藏而11显示的时候,系统会自动把填充1的View传递过来,注意看代码Adapter的getView方法
@Override
public View getView(final int position, View convertView, ViewGroup parent)
这里的converView就是1的view,一般的做法会把这个view拿来复用,作为11的view。
当我们固定listview的高度时(fill_parent或直接固定高度),那么listview很容易就能计算出容器内可以显示多少行。但如果我们使用了“wrap_content”,只有在屏幕内控件完全加载后才知道到底能显示多少行数据时,ListView自身便会做一些尝试性计算。在源码中可以发现一些叫做onMeasure的方法,目测是做此用处(源码略显复杂,没读透)。
当listview计算出屏幕一共需要多少行后,如果listview自身高度不变,那么它的容纳的行数就不会变,使用getChildCount()可以得到它的最大行数。
再回到原来的问题,为什么最后一次取得的结果不是listview的第一行呢? 将listview设置为“wrap_content”后用下面的测试代码,看下输出。
//获取当前listview的个数 相等输出个数和站点名 不相等输出个数和"无"
if(listViewgetChildCount() == position)
{
//child个数 当前position位置 +站名
Logi("", listViewgetChildCount()+" "+position+" "+coordInfostationname);
}
else {
//child个数 当前position位置+无
Logi("", listViewgetChildCount()+" "+position+" "+"无");
}
额 就是类似这种
<view wx:for="{{array}}" wx:for-index="idx" wx:for-item="itemName">
{{idx}}: {{itemNamemessage}}
</view>
条件渲染 出来的效果都是纵向的 如何把他变为横向的?
我在这个外面加过scrollview,但是像这种
<scroll-view scroll-x="true" class="col3-img-list">
<view wx:for="{{item}}" class="listview">
<image class="image" src="{{itemsrc}}"></image>
<text class="text">{{itemtitle}}</text>
</view>
以上就是关于vb2005 listview的subitem 编辑问题~~~~~~~全部的内容,包括:vb2005 listview的subitem 编辑问题~~~~~~~、listview调用getview为什么会执行三次、微信小程序,weixin,求微信小程序的横向LISTVIEW怎么设置等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)