为什么我写的ListViewItem lvi = new ListViewItem(); 必须要有参数才行?

卧槽这是我的昵称吗 2013-08-27 02:23:09
ListViewItem lvi = new ListViewItem();
错误 “System.Web.UI.WebControls.ListViewItem”不包含采用“0”个参数的构造函数

但是我在网上随便找的例子,都是这样写的啊,没见new ListViewItem(); 还带了参数的

而且msdn上

ListView listView1 = new ListView();
listView1.Bounds = new Rectangle(new Point(10,10), new Size(300,200));

// Set the view to show details.
listView1.View = View.Details;
// Allow the user to edit item text.
listView1.LabelEdit = true;
// Allow the user to rearrange columns.
listView1.AllowColumnReorder = true;
// Display check boxes.
listView1.CheckBoxes = true;
// Select the item and subitems when selection is made.
listView1.FullRowSelect = true;
// Display grid lines.
listView1.GridLines = true;
// Sort the items in the list in ascending order.
listView1.Sorting = SortOrder.Ascending;


而我放在本地写算么listView1.AllowColumnReorder这些属性压根就没有啊?
...全文
327 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
雪狐 2013-08-27
  • 打赏
  • 举报
回复
汗。。。。。
全栈极简 2013-08-27
  • 打赏
  • 举报
回复
你看错了。winform的listview有AllowColumnReorder,你的是webform的,没有AllowColumnReorder。
  • 打赏
  • 举报
回复
引用 2 楼 guwei4037 的回复:
ListView lv = new ListView(); lv.AllowColumnReorder = true; 是可以的。注意大小写。
“System.Web.UI.WebControls.ListView”不包含“AllowColumnReorder”的定义,并且找不到可接受类型为“System.Web.UI.WebControls.ListView”的第一个参数的扩展方法“AllowColumnReorder”(是否缺少 using 指令或程序集引用? 我真的不明白。。。
全栈极简 2013-08-27
  • 打赏
  • 举报
回复
ListView lv = new ListView();
lv.AllowColumnReorder = true;
是可以的。注意大小写。
本拉灯 2013-08-27
  • 打赏
  • 举报
回复
你找的是WINFORM的代码。。
private void button3_Click(object sender, EventArgs e) { string number = textBox2.Text; string bookname = textBox3.Text; string press = textBox4.Text; string name = textBox6.Text; string price = textBox5.Text; DateTime dt= dateTimePicker1.Value; string bookid = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); MessageBox.Show(bookid); string sql1 = "update book set number='{0}',bookname ='{1}',press='{2}',price='{3}',dt='{4}'where bookid ='{5}' "; sql1 = string.Format(sql1,number, bookname,press,price,dt,bookid); string sql2 = "update categorybook set name='{0}'where categoryid in(select categoryid from book where bookid='{1}')"; sql2 = string.Format(sql2, name, bookid); SqlConnection conn = new SqlConnection(); conn.ConnectionString="server=20110810-1559\\SQLEXPRESS;database=stums;integrated security=true"; //conn.ConnectionString = "server=XP-201108091130\\SQLEXPRESS;database=stums;uid=sa;pwd=0"; conn.Open(); SqlTransaction st = conn.BeginTransaction(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; try { cmd.CommandText = sql1; cmd.ExecuteNonQuery(); cmd.CommandText = sql2; cmd.ExecuteNonQuery(); st.Commit(); Showmsg(); MessageBox.Show("修改成功"); } catch { MessageBox.Show("修改失败"); } } private void button9_Click(object sender, EventArgs e) { if (dataGridView1.RowCount > 0) { dataGridView1.SelectAll(); } } private void button10_Click(object sender, EventArgs e) { while(dataGridView1.SelectedRows.Count > 0) { DataGridViewRow dv = dataGridView1.SelectedRows[0]; dv.Selected = false; } } private void button11_Click(object sender, EventArgs e) { string sql = "select * from book "; SqlConnection conn = new SqlConnection("server=20110810-1559\\SQLEXPRESS;database=stums;integrated security=true"); //SqlConnection conn = new SqlConnection("server=XP-201108091130\\SQLEXPRESS;database=stums;uid=sa;pwd=0"); conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { ListViewItem lvi = new ListViewItem(); lvi.Text = sdr["number"].ToString(); lvi.SubItems.Add(sdr["bookname"].ToString()); lvi.SubItems.Add(sdr["price"].ToString()); listView1.Items.Add(lvi); } sdr.Close(); conn.Close(); }

111,111

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧