• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 324
  • Last Modified:

How to make a column editable on a listview

I have a listview control on a mobile application, and I want to make the last column editable (so the user can enter in a quantity). How would I go about doing this?

private void DisplaySKULots()

            using (ABISS3ServiceB.BasicHttpBinding_Container containerClient = new ABISS3ServiceB.BasicHttpBinding_Container())
                containerClient.Url = NewABISS3ServiceURL(containerClient.Url);
                ABISS3ServiceB.ContainerItem[] containeritem = containerClient.ContainerItems_GetByLPN(textBoxLPN.Text.Trim());


                if (listViewPalletBreakdown.Columns.Count == 0)
                    this.listViewPalletBreakdown.CheckBoxes = false;
                    listViewPalletBreakdown.Columns.Add("SKU", 75, HorizontalAlignment.Left);
                    listViewPalletBreakdown.Columns.Add("Lot", 75, HorizontalAlignment.Left);
                    listViewPalletBreakdown.Columns.Add("Qty", 65, HorizontalAlignment.Left);
                    listViewPalletBreakdown.Columns.Add("UoM", 65, HorizontalAlignment.Left);
                    // TODO: The column below is the only I want to make editable
                    listViewPalletBreakdown.Columns.Add("Qty to New LPN", 65, HorizontalAlignment.Left);

                foreach (ABISS3ServiceB.ContainerItem item in containeritem)
                    listViewPalletBreakdown.Items.Add(new ListViewItem(new string[] { item.VendorSku_Ref, item.LotCode_Ref, item.ConversionItemQty_Ref.ToString(), item.ConversionUnitOfMeasureDesc_Ref, item.VendorProductDescription_Ref }));

Open in new window

1 Solution
Unfortunately that is not allowed without jumping through a few hoops. from MSDN:
Unlike ListViewItem objects, ListViewItem.ListViewSubItem objects cannot be edited directly by the user (the user can edit ListViewItem objects if the LabelEdit property of the ListView control is set to true).

I'm not sure if any of the following two ideas will work but you can try and see how much effort you will need for it. IMO, DataGridView would be easier to use here.
1. Rearrange the columns so that the column you want to edit is the main item but is shown last in the UI
2. Derive a new class from ListViewSubItem and implement the drawing and key strokes handling yourself.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now