|
Hi,
I'm working on an application of which requires me to have one list-box to hold data.
I'm having a little issue when deleting an object from a list-box. The issue comes into play when I fill the list-box with items from TWO separate lists.
Normally to delete the object I would get it's index and then remove it from the list in a separate class then reload the list-box to reflect the changes but in certain instances I need to fill the list-box with objects from two different lists and determining the origin of the object to delete from one of the two lists, well I'm not entirely sure how to do this.
this code is populating the list-box control.
ViewListBox.Items.Clear();
List listOfPickups = visits.listPickups();
List listOfdeliveries = visits.listDeliveries();
ViewListBox.Items.AddRange(listOfPickups.ToArray());
ViewListBox.Items.AddRange(listOfdeliveries.ToArray());
this is how i delete when i am only loading the listbox from one list.
if (ViewListBox.SelectedIndex < 0)
{
EditSelectBtn.Enabled = false;
DeleteSelectBtn.Enabled = false;
}
else
{
if (MessageBox.Show("are you sure you want to delete the selected item?", "Are You Sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
visits.removePickup(this.ViewListBox.SelectedIndex);
updateList("pickups");
}
else
{
ViewListBox.ClearSelected();
}
}
Any help would be greatly appretiated.
modified 11-Mar-21 21:01pm.
|
|
|
|
|
I don't work with winforms anymore but I believe there will be a tag property on the listboxitem, I would put an identifier in there. OR add a hidden column (width = 0) with the identifier.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If the list box doesn't sort (so always displays the items from the first list first and items from the second list below that), the easiest solution would be to compare the index to delete with the size of the first list. If the index is too large, just subtract firstList.Count to get the index to remove from the second list.
|
|
|
|
|
Thank you i tried this and it works perfectly!
modified 11-Mar-21 21:01pm.
|
|
|
|
|
hi men
I have a listView called lw1.
When I use lw1.selectedItem, I can check which item is selected.
But, how I can know which item is alone highlighted by mouse cursor?
note:http://dl.dropbox.com/u/45898865/Immagine.jpg[^]
in picture 1
gimppoi is selected with one click of mouse cursor
in picture 2
gimppoi is selected with one click of mouse cursor
poweooooooooo has alone mouse cursor over the line
modified 3-Dec-12 16:01pm.
|
|
|
|
|
Some grids (not sure about listviews) allow you to select the item on mouseover. Otherwise you need to handle the mouseover event, use hittest to identify the record and decide what to do with it!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
good idea
I had tried it yesterday without success.
private void buttonGV_Click(object sender, RoutedEventArgs e)
{
Attivita attivita = null;
for (int i = 0; i < listViewAttivita.Items.Count; i++ )
if ( listViewAttivita.IsMouseOver )
attivita = listViewAttivita.Items[i] as Attivita;
if ( listViewAttivita.IsMouseOver )
this test is needless, because I want know which row is selected. That test told me if the mouse is over one of all ListView rows.
Can you tell me what I should search to understand which row has the mouse over?
this is the XAML part. Does it help?
<ListView ItemsSource= "{Binding AttivitaCollection, UpdateSourceTrigger=PropertyChanged}" Height="206" HorizontalAlignment="Left" Margin="12,33,0,0" Name="listViewAttivita" VerticalAlignment="Top" Width="auto" SelectionChanged="listViewAttivita_SelectionChanged">
<ListView.Resources>
<med:ImageConverter x:Key="imageConverter"/>
</ListView.Resources>
<ListView.View>
<GridView>
<GridViewColumn Header="Azioni registrate" Width="150" DisplayMemberBinding="{Binding nome, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<GridViewColumn Header="Stato" Width="auto" >
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Width="24" Name="buttonGV" Click="buttonGV_Click" Height="24" Background="Transparent" BorderBrush="Transparent">
<Image Source="{Binding Path=imgStato, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource imageConverter}}" />
</Button>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
|
|
|
|
|
I would post this in the WPF/Silverlight forum, there are some guys there who have a very deep knowledge. At a guess you probably need a trigger on the listview servicing the mouseover event.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi,
I would like to ask which way you prefer t store variable which could be available for read/write? do you prefer to store in App.Config or Windows Registry is still best to use?
Thanks,
Jassim[^]
Technology News @ www.JassimRahma.com
|
|
|
|
|
I prefer text files. Is it a WinForm app, a WebApp, a widget? Does it run under limited permissions, or in the users' context?
|
|
|
|
|
It's winForm and as you know standard users won't have access to C:\Program Files so will the App.config work in this case?
Technology News @ www.JassimRahma.com
|
|
|
|
|
I'd use the Settings-file, not the App.Config. Which, by the sound of it, is an application-level configuration, not user-level.
|
|
|
|
|
I roll my own config files (XML) and read and write to them.
I never touch the Registry.
|
|
|
|
|
So rather than use the infrastructure that's there for you, tested, and with reams of documentation available - you choose to roll your own?
Wow!
|
|
|
|
|
Of course. It works the way I want, not the way someone else who knows nothing of what I do thinks everyone should do it.
J4amieC wrote: with reams of documentation
That would be a clear reason not to use it. My way requires no documentation, it is therefore superior.
|
|
|
|
|
Do your xml files properly handle multiple NT accounts each with different settings like the registry does?
Do your xml files handle concurrent write by eg, configuration tool, like the registry does?
Can your xml files be modified easily by domain login scripts like the registry does?
Can your xml files be centralized into AD for centralized enterprise management? Like registry entries can be?
|
|
|
|
|
Of course not, I don't want that.
Can registry entries be stored on a flash drive and used on whatever system I happen to be using only while I'm using the software?
|
|
|
|
|
or anyone like done c# or c c+ if anyone interesws email me
|
|
|
|
|
again....you posted something completely incomprehensible.
|
|
|
|
|
I believe your English is poor.
what you mean by interesws ? is this interest or interview ??
One more point, do not expect email from codeproject. people will help you by posting question's answer here. that may help others as well.
For interest, you can read top rated articles in codeproject
For interview, you should read ebooks. that will help you to understand basic concepts. reading interview question never help when there is some smart interviewer.
just make sure whatever you read, you are conceptually clear for that.
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
i want know want do work need do i like see terry is interresed in spades for me
|
|
|
|
|
Ms Cindy, I would report this but it is neither spam or abuse, just incomprehensible. Change you profile to reflect your country of origin, your first language is obviously not english. Get someone to help you who knows english!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
i agree with you. OP is posting question with less information and may be he is not good with english.
Thanks
-Amit Gajjar (MinterProject)
|
|
|
|
|
I think it might be spam.
|
|
|
|
|
...
modified 1-Dec-12 10:27am.
|
|
|
|