1
我在我的列表視圖(xaml) 內有一個gridview我通過索引值在我的列表視圖中設置選定的項目。這工作正常。集中選擇列表視圖
現在我想鍵盤焦點在選定的項目上。
我可以將焦點設置到列表視圖本身,但不能在列表視圖中選定的項目。
// Set selected item at index : i
listview1.SelectedIndex = i;
// Sets focus to listview
listview1.Focus();
// Try to set focus to selected item
ListViewItem myitem = listview1.Items[i] as ListViewItem;
myitem.Focus();
dgrid1.xaml
<ListView Name="listview1" >
<ListView.View>
<GridView ColumnHeaderToolTip="Multiple Category Information">
<GridViewColumn DisplayMemberBinding="{Binding Path=Enquiry_Number}" Header="Enquiry number"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Consignee_Ref}" Header="Consignee reference"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Booking_Reference}" Header="Booking reference"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Contract_Number}" Header="Contract Number"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Invoice_Number}" Header="Invoice Number"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Date_Invoice}" Header="Invoice Date"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Status}" Header="Status"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Period_Enquiry}" Header="Period Enquiry"/>
<GridViewColumn DisplayMemberBinding="{Binding Path=Consignee}" Header="Consignee"/>
</GridView>
</ListView.View>
</ListView>
dgrid1.xaml.cs
// Call the DataManager Class which will collect the data and fill the data set with it
DataManager.BindFilteredData(dts);
public static void BindFilteredData(DataSet dts)
{
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConString"].ConnectionString))
{
sql = "SELECT Enquiry_Number, Consignee_Ref, Booking_Reference, Contract_Number, Invoice_No, Date_Invoice, [Status], Period_Enquiry, Consignee FROM ConsHead";
using (SqlDataAdapter adapter = new SqlDataAdapter(sql, connection))
{
adapter.Fill(dts);
}
}
}
你不能使用listview1.Selecteditem.focus? – Terry
listview1.SelectedItem.focus(); 這給出了「對象不包含'焦點'的定義和沒有擴展方法...等 –
你可以顯示一些xaml(在列表視圖中嵌套的gridview)使我能夠複製你的問題 – Terry