|
Since you're using an ItemsControl, there's no notion of
"selected items" so you'll have to track that somehow yourself.
I assume you're doing that somehow already if you know certain items
need their listbox selection changed.
Once you have the ItemsControl item(s) which you need to manipulate, for each item
you can get its template and use FindName() to get at its ListBox (you'll need to give
that template ListBox a name).
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Collin Jasnoch wrote: I am not exactly sure what you mean. The Listbox in the template? How can I give it a name? Even if I name it, it is not valid since it is in a DataTemplate.
I was referring to using FindName() to find an element at runtime which was created
through a template (i.e. the "Listbox Inside of a Template"). You'd use x:Name to give
it a name, and find the element with FindName().
If you already have a solution then never mind
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
BTW, I'm still working with your original post where you stated
"I would like a way to remove the selection from specific listboxes."
To do that, you set the listbox's SelectedIndex to -1 (the user can also
do this with Ctrl-Click).
To set the listbox's SelectedIndex to -1, you need the actual listbox object,
which was created via a template, so you use FindName() to get the object at
runtime (since it doesn't exist at design time).
Now you're discussing what you do in response to a listbox's selection changing,
so I'm probably way off topic at this point
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
|
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It is simple only. Access the list box items and set the selected index to -1.
e.g.
MyViewModel context = this.DataContext as MyViewModel ;
var results = lstBoxCity.SelectedItems;
bool flag = true;
foreach (RefGeneralValue rval in results)
{
if (rval.RefGeneralValueId == 0)
{
lstBoxCity.SelectedIndex = -1;
flag = false;
break;
}
}
if (flag == true)
{
}
N.B.~ RefGeneralValue is a entity that we are using in our project.
It is as follows (given only for ur reference)
[Serializable]
[DataContract]
public class RefGeneralValue : BaseDomainClass
{
public RefGeneralValue();
[DataMember]
public virtual DateTime? ModifyDate { get; set; }
[DataMember]
public virtual string RefGeneralTypeId { get; set; }
[DataMember]
public virtual string RefGeneralValueCode { get; set; }
[DataMember]
public virtual string RefGeneralValueDescLong { get; set; }
[DataMember]
}
Thanks
Niladri Biswas
|
|
|
|
|
I have used a Barchart in a Client Report Definition (.rdlc) subreport which works properly when shown individually but does not work when integrated with a main report. While showing the Main report, the main report and all its subreports work absolutely fine except the one using BARCHARTS. This barchart subreport comes blank.
Thanks & Regards
Jitesh
|
|
|
|
|
Hi,
I am developing one application in that I stored images from xaml page using generic handler and i am retrieving image from database using generic handler.I have written the database code to retrieve image in generic handler and i am calling that handler page in xaml page.Retrieving the image is working for me now.But my problem is how to retrieving images from DB and bind it to Datagrid in silverlight.And how to call data grid function and where to call that function.I referred the following link to bind images to datagrid but its not working for me and i am not getting how they are calling datagrid function.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=264&AspxAutoDetectCookieSupport=1
Please can anybody help me solve this problem.
Thanks in advance
Pavani
|
|
|
|
|
pavanip wrote: i am not getting how they are calling datagrid function
Calling what datagrid function?
There is an event handler added to the datagrid, and the only access from
code to the datagrid is to the datagrid's Columns property.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
In datagrid I used the following attribute to call that function
LoadingRow="dGrid_LoadingRow"
But i am not getting when it will be fired and the code executes.I have written the following code in that event
private void dGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
FrameworkElement ele = dGrid.Columns[4].GetCellContent(e.Row);
string url = "http://localhost:52614/Display.ashx";
Uri imageUri = new Uri(url, UriKind.RelativeOrAbsolute);
(ele as Image).Source = new BitmapImage(imageUri);
}
But its not executing when i debug it line by line. Or can you please tell me tell me how to bind images to datagrid in silverlight.
|
|
|
|
|
pavanip wrote: But its not executing when i debug it line by line.
Line by line? Put a breakpoint in there instead and see if it gets hit.
If it doesn't then you've either not provided any row data to the control
or you've done something wrong adding the event handler to the control.
The handler should get hit for every row the control creates.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a project that I'm working on. Currently, I'm using 3 Expanders in my xaml file and I've got a listbox in within each expander. I load each listbox by binding the name member of the Person object to the DisplayMemberPath. I load 3 different collections with a Person objects representing a list of males, females, and juveniles. Once the objects are loaded I assign them each to the item source of their respected Listbox:
Collection<person> male = sql.getinfo('M'); //returns a collection of male names and info.
Collection<person> females = sql.getinfo('F');
maleListBox.ItemSource = male; //malelist represents listbox
FemaleListBox.ItemSouce = females;
When I click on the name of the male in the ListBox I cast the object so that I can disapply it in serveral labels. The casting is occurring in a method called generic_ListBox:
private void genericListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
lblName.Content = ((personData.person)((ListBox)sender).SelectedItem).personName;
...
}
I'm doing this so that I can get the information from each additional ListBox which is in it's own seperate expander.When I scroll through the list all is fine. The name shows the current person's name with the respected data; however if I toggle between the male list and female list for example the data is not updating. For example: I click on Todd Smith (it shows), I then click Cindy Jackson it shows, if I click back on Todd Smith Cindy Jackson's info still shows.
It seems that the selectedChanged event is not being fired because in the male list Todd Smith is still selected but has lost focus. I've tried changing focus but it gives me a null error. The closes that I have come was by calling a UnSelectAll() method and checking for a null value; I not a fan of this because it doesn't tell me which name is selected in the list. Can someone help? Any ideas as to how to get the item to show up when I click on a item that regains focus and is already selected?
Terrance C.
modified on Wednesday, May 20, 2009 8:45 PM
|
|
|
|
|
What about handling the LostFocus event on the listboxes and in the handler set
SelectedIndex of the listbox to -1?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Unfortunately, that gives me a NullReferenceException. Thanks, for the suggestion.
Terrance C.
|
|
|
|
|
Then don't use references that are null
On a more serious note - what are you using that's null in an
event handler?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Very funny....
If I set the first expander to a selectedindex = -1 then when I go retrieve an object from a different expander I get the nullreference exception stating Object Reference to set to instance of an object.
See I have 3 listboxes and they hold a reference to the name portion of Collection<person> object.
I have a generic_Selectionchange event handler that casts the selected item back to the person object when ever there is a selection change in the listbox
lblPersonId.Content = ((personData.Person)((ListBox)sender).SelectedItem).personId;
If the selectedindex is set to -1 then whenever that listbox regains focus it throws the error.
Terrance C.
|
|
|
|
|
Tee123 wrote: If the selectedindex is set to -1 then whenever that listbox regains focus it throws the error.
Right....I don't understand why you don't check for that condition and take the
appropriate action - you should have been doing that anyway, right?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm new in WPF programming. I created a custom window template and I created the code behind class as a ResourceDictionary. I can modify my windows layout using Style="{DynamicResource MyCustomWindow}
Everything works good, but now I added two buttons Save and Exit and I want generate two different behaviors, but the ButtonClick evente are in the template code behind and I don't know how to raise an evenmt or call a method in the host window.
Thanks.
Armando
|
|
|
|
|
Use either Routed Event or ICommand class for the same.
Niladri Biswas
|
|
|
|
|
I have a togglebutton template which have vsm to do something on checked, pressed etc.
I want to add Polygon inside that template and add storyboard to it....
I want to add it from .cs file...so that I can change the coordinates of polygon dynamically as the size of the button content....
How can I do that?
|
|
|
|
|
Did you take a look at the PathGeometry object?
You could generate the polygon in blend and then assign it through code (i.e. your cs file).
|
|
|
|
|
Do u have any code snippet/link to just give me some idea and make things clear?
Also one thing to note that this polygon should be inside buttton template so that I can give the animation?
|
|
|
|
|
|
Hi..
I am using hierarchical data template in tree view in my wpf application using mvvm pattern.
Binding of data using observable collection done successfully through viewmodel..
But my problem is in getting selected item..
Can anybody tell me how to get selected item in treeview in mvvm pattern.....?
|
|
|
|