Numbered Listbox

Numbered listbox

This should get you started:

http://weblogs.asp.net/hpreishuber/archive/2008/11/18/rownumber-in-silverlight-datagrid-or-listbox.aspx

It says it's for Silverlight, but I don't see why it wouldn't work for WPF. Basically, you bind a TextBlock to your data and use a custom value converter to output the current item's number.

How do I display numbers in the List Box?

You will need to add a loop. Something like this:

Option Explicit

Private Sub btCalculate_Click()
Dim i As Integer

lstCount.Clear

For i = Val(txtFrom.Text) To Val(txtTo.Text)
lstCount.AddItem i
Next
End Sub

Where lstCount is a ListBox.

Need to format automatically numbered rows in WPF ListBox

Your Profile type should have an Index property of some sort, which you should set. AlternationCount "enables alternating containers to have a unique appearance," so I believe you're not using that correctly. When you have that property added to your Profile type then you can do something for your ItemTemplate like:

<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100">
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock HorizontalAlignment="Right"
Margin="0 0 5 0"
Grid.Column="0"
Text="{Binding Index}"/>
<TextBlock Grid.Column="1"
Text="{Binding}" />
</Grid>
</DataTemplate>

How to count items in listbox using tkinter?

You can ask the listbox to return you the index of the last element:

the_listbox.index("end")

The number that is returned corresponds to the number of items in the listbox.

If you want to show it in "some box", you just need to insert the box or configure it, depending on what you mean by "some box". If it's an existing label then it would be something like:

count = the_listbox.index("end")
the_label.configure(text=f"{count} items in listbox")

Adding numbers from a list of integer to listbox

Currently you're adding a single item to the list, which is the List(Of Integer) object. You need to add each item in the list separately, like this:

For Each i As Integer In ListOfNumber
listBox1.Items.Add(i)
Next

Or, more simply:

listBox1.Items.AddRange(ListOfNumber)

As was already mentioned in the comments, but bears repeating, regex is typically the wrong tool for the job when you're parsing HTML. Using an HTML parser/DOM would be preferable in most cases.

How to create a listbox having index numbers followed with list item

I think best option for you is using DataGridView with two columns:

  • DataGridViewButtonColumn, AutoSizeMode = AllCells
  • DataGridViewTextBoxColumn, ReadOnly = true, AutoSizeMode = Fill

Also RowHeadersVisible and ColumnHeadersVisible to false. Result:

Sample Image

Code:

string[] members = { "Beverages", "Condiments", "Confections" };
dataGridView1.DataSource = members.Select((x, i) => new { Value = x, Index = i })
.ToList();

Also you need to set columns DataPropertyName to Index and Value.

UPDATE (for .NET 2.0):

string[] members = { "Beverages", "Condiments", "Confections" };
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = members;

Subscribe to CellFormatting event:

void dataGridView1_CellFormatting(object sender, 
DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 0)
{
e.Value = e.RowIndex;
return;
}

e.Value = dataGridView1.Rows[e.RowIndex].DataBoundItem;
}


Related Topics



Leave a reply



Submit