First item in a List is always selected
In this scenario we can pass clicked item like baton from ForEach
to Alert
to FullScreen
to Details
. And, of course, we should move corresponding modifiers out of cycle, they don't need to be applied to each row.
Here is a modified code. Tested with Xcode 12.1 / iOS 14.1.
struct ContentView: View {
var array: [Object] = [Object(id: .init(),property: 1),Object(id: .init(),property: 2),Object(id: .init(),property: 3)]
@State var alertItem: Object?
@State var selectedItem: Object?
var body: some View {
NavigationView{
List{
ForEach(array){ item in
VStack{
Text(String(item.property))
}.onTapGesture(){ self.alertItem = item}
}
}
.alert(item: $alertItem) { item in
Alert(title: Text("show details view?"), message: Text(""),
primaryButton: .default (Text("Show")) {
selectedItem = item
},
secondaryButton: .cancel()
)
}
.fullScreenCover(item: $selectedItem){ DetailsView(property: $0.property) }
}
}
}
How to make default select the first item in mat-list in angular
According to the Angular Material Docs, mat-list-item
doesn't have a selected input property that you can apply to the element. however mat-list-option
does.
as such, if you switch to using mat-list-option you can leverages properties [selected]
and [value]
why listbox always selecting first item true
After filling listbox
just write this line
lstBBoxSkill2.SelectedIndex = -1;
or
lstBBoxSkill2.ClearSelected();
always getting the value of first item in list when posting
Your modal actually passed the correct id, but the button does not trigger correct modal because the data-target
is always the same. That is why you always get the modal with the first id.
Add an index to specify the modal id:
@{ int i = 0; } //add this...
@foreach (var item in Model.GetContracts)
{
<tr>
<td>@item.Plate</td>
//....
<td>@item.Id</td>
//change here...
<td><Button type="button" class="btn btn-success" data-target="#Returned_@i" data-toggle="modal" onclick="getId">إغلاق العقد</Button></td>
<td>
//change here...
<div class="modal fade" id="Returned_@i" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle"></h5>
<button type="button" cl ass="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="post" asp-route-id="@item.Id">
@item.Id
<input type="date" asp-for="@Model.Update" />
<input type="submit" class="btn btn-primary" />
</form>
</div>
</div>
</div>
</div>
</td>
</tr>
i++; //add this...
}
How to select the first item in list by default with jquery
With css only create class active
.active {
background-color: #CCC;
}
Add this class to your first tag
<a class="mdc-list-item active" tauxPlafonds="PSS" data-toggle="tooltip" data-placement="top" style="cursor:pointer;">
Plafond sécurité sociale
</a>
To remove class use this function to add click event for all links except for the first
$("a.mdc-list-item:not(:first)").on("click", function (event) {
$("a.mdc-list-item:first").removeClass("active");
});
ListBox always auto selects first item
Well i tried this using FocusManager.FocusedElement .. and made the intial focus to
listbox itself.. so it has the focus..but no element is selected..
if u press down or tab ..the 1st element of the listbox will be selected...
<Window
......
FocusManager.FocusedElement="{Binding ElementName=listbox2}">
<ListBox x:Name="listbox2" HorizontalAlignment="Left"
VerticalAlignment="Bottom" Width="117.333" Height="116"
Margin="30.667,0,0,30">
<ListBoxItem>Jim</ListBoxItem>
<ListBoxItem>Mark</ListBoxItem>
<ListBoxItem>Mandy</ListBoxItem>
</ListBox>
How to get the first element of the List or Set?
Collection c;
Iterator iter = c.iterator();
Object first = iter.next();
(This is the closest you'll get to having the "first" element of a Set
. You should realize that it has absolutely no meaning for most implementations of Set
. This may have meaning for LinkedHashSet and TreeSet, but not for HashSet.)
Related Topics
How Flatmap API Contract Transforms Optional Input to Non Optional Result
How to See Which Version of Swift I'M Using
Swift @Escaping and Completion Handler
Downcasting Optionals in Swift: As? Type, or As! Type
Tabview Resets Navigation Stack When Switching Tabs
How to Use Userdefaults With Swiftui
What Is Difference Between Optional and Decodeifpresent When Using Decodable For Json Parsing
How Does Collisionbitmask Work? Swift/Spritekit
How to Remove the Left and Right Padding of a List in Swiftui
Swift 4 Decodable - Dictionary With Enum as Key
Nsfilemanager Fileexistsatpath:Isdirectory and Swift
Firebase Getting Data in Order
Using a Dispatch_Once Singleton Model in Swift