I'm binding ListView control to DataTable. The DataTable have a column named ProductID. Is there any way to hide this column, because I'm gonna need it's value later?
+2
A:
I'll just address the UI angle. You can hide it by setting the column width to 0. For example, if the ID is bound to the 2nd column:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
listView1.Columns[1].Width = 0;
listView1.ColumnWidthChanging += listView1_ColumnWidthChanging;
}
private void listView1_ColumnWidthChanging(object sender, ColumnWidthChangingEventArgs e) {
if (e.ColumnIndex == 1) {
e.NewWidth = 0;
e.Cancel = true;
}
}
}
It's not quite ideal, the user can get confuzzled by the 'splitter' cursor that shows up when she's a bit too far to the right of the column divider. That's very hard to fix.
Hans Passant
2010-08-22 13:14:49