Inserting and displaying a lot of items using Listbox - c#

I am using listBox to show a lot of items (number of items>1000000). But it can show only the items which are in integer range. I have searched a lot, but I found nothing.
I want to know if there is any way to make listBox show items in "long" range?

Related

c# listbox numerical order of items

Hello I'm searching throught internet for hours but still I can not find the answer. (or I just don't know how to ask)
I need a simple numerical order of items in listbox fe. I am adding every 3rd items to listbox from txt file.
When I have this in txt file:
Acc 4
name4
pass4
Acc 5
name5
pass5
I'll add to listbox only Acc4 and Acc5
And now when I select some item in listbox I want to know which one is selected but I don't want fe.: Acc6 (is selected) but I want to know Acc6is 3nd one in listbox (then order is 2)
PS: sorry for my end and thx for help
If you are looking for the index of the selected item in a listbox try
{listBoxName}.SelectedIndex
This will give you the index (0 based) of a selected item. https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.listbox.selectedindex?view=netframework-4.7.2
If you want the item try
{listBoxName}.SelectedItem
This gives the currently selected item https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.listbox.selecteditem?view=netframework-4.7.2

listview- System.ArgumentOutOfRangeException

I have a listview which has 7 columns. I want to add information on each column, but when it reaches the subitem 2 from the listView I get a System.ArgumentOutOfRangeException even though I have that subitem.
Any idea why I get this error? I've tried to search for it but I haven't found a similar case.
This is the part of the code where I get that error:
if (seen == true)
listView1.SelectedItems[0].SubItems[2].Tag = "Seen";
else
listView1.SelectedItems[0].SubItems[2].Tag = "Not Seen";
You probably do not have all those SubItems in each item.
Or maybe nothing is selected? (Note that the SelectionChanged event gets called when an Item is unselected as well!)
Note that every Item in a ListView can have its own number of SubItems, no matter how many Columns you have created. These only provide a space to display the data, not slots you can access without creating SubItems !
Therefore we must test it before we access it! In other words: The ListView structure is not a 2d array but a jagged array!
This could be a possible check..:
if ( listView1.SelectedItems[0].Count > 0 &&
listView1.SelectedItems[0].SubItems.Count > 2 )
listView1.SelectedItems[0].SubItems[2].Tag = seen ? "Seen" : "Not Seen";
..but you know your code better and may well find a nicer way of doing the necessary tests..
Just do not rely on the number of SubItems being equal to the number of Columns. They are not related at all and either may be greater in each Item!

Group items by date in a listview

I would like to create groups by day for my items in a ListView (like a LongListSelector in WP7). I succeed with alphabetical items thanks to the CharacterGroupings class but I try to find the best way with timestamp. Do you have any idea to help me sorting items by creating by month/day, then put all the relating items in these groups ?

Fast method to get row indices of selected cells in a DataGridView

I want to obtain a list of the row indices of selected cells in a DataGridView.
I was previously using SelectedCells to get this information, but this takes around 40 seconds when there are 2 million rows and all are selected.
this.SelectedCells
.Cast<DataGridViewCell>()
.Select(c => c.RowIndex)
On Msdn it says that SelectedCells is slow for large grids, but apart from the special case where all cells happen to be selected, does not offer many alternatives. What if all but 1 row/cell is selected?
Is there a faster method?
It's a hack, but I eventually reverted to using reflection to access the private field DataGridView.individualSelectedCells, which is a linked list of the selected cells. This is much faster than accessing DataGridView.SelectedCells, though obviously less robust.

using TableLayoutPanel and dynamic Combobox in windows form C#

I need some serious help with this. I've searched on the forums, googled, and expermimented as much as I can....all to no avail.
Here's the problem.
I'm using a TableLayoutPanel to dynamically configure a form based on values from a database.
To the TableLayoutPanel, I dynamically add -
1 Label,
1 Textbox,
1 Button,
1 Combobox
Here's the root of the problem -
If I have 2 or more rows in the TableLayoutPanel, all the Comboboxes
change at the same time.
What do I have to do to only get 1 Combobox to change at a time ?
The datasource is the same, so it treats any change in one combobox connected to the datasource as a change to any other connected comboboxes. To get around that simply make a temporary string array and copy over the information to that array from the original source, from there simply have it be the datasource of the combobox.

Categories

Resources