C#覆盖CheckedBoxList显示成员

时间:2017-11-11 11:00:31

标签: c# .net winforms checkedlistbox

有没有办法为CheckedListBox设置多列显示成员而无需创建将属性值合并在一起的新类?比如重写DisplayMember之类的东西?

我正在使用C#4.0 VS 2015

1 个答案:

答案 0 :(得分:1)

您不需要覆盖if(isset($_GET['cu_id'])){ $id = $_GET['cu_id']; $query = mysqli_query($conn,"SELECT * FROM customer WHERE cu_id = '$id'") or die (mysqli_error($query)); while($row = mysqli_fetch_assoc($query)){ echo ' <form method="POST"> <input type="hidden" name="id" value ="'.$row['cu_id'].'"/> <input type="text" name="c_name" value ="'.$row['cu_name'].'"/> <input type="text" name="c_email" value ="'.$row['email'].'"/> <input type="text" name="c_phone" value ="'.$row['phone'].'"/> <input type="text" name="coun_id" value ="'.$row['cu_id'].'"/> //delete this line if they cant edit it <input type="text" name="card_id" value ="'.$row['cu_id'].'"/>//delete this line if they cant edit it <input type="submit" name="submit" value ="Send"/> </form>'; } if(isset($_POST['submit'])){ $id = $_POST['id']; $c_name = $_POST['c_name']; $c_email = $_POST['c_email']; $c_phone = $_POST['c_phone']; $query = mysqli_query($conn,"UPDATE customer SET cu_name = '$c_name', email = '$c_email', phone = '$c_phone' WHERE cu_id = '$id'") or die (mysqli_error($query)); if ($query){ echo '<script>alert("Update Successful!");</script>'; } } 。相反,您可以处理DisplayMember Format事件,这样您就可以为每个元素提供自定义显示值。

  

在ListControl中的每个可见项之前引发Format事件   格式化。处理此事件可让您访问字符串   显示此列表项,通过的CheckedListBox属性   ListControlConvertEventArgs

事件的事件参数包含Value属性,该属性是项目背后的对象,因此您可以在此处混合一些属性并将结果分配给ListItem

例如,假设您在e.Value中显示List<Product>,我们可以通过以下方式自定义外观:

checkedListBox1
相关问题