我的列表视图(xaml)中有一个网格视图我通过索引值在我的列表视图中设置了所选项目。这工作正常。
现在我希望键盘焦点位于所选项目上。
我可以将焦点设置到列表视图本身,但不能设置到列表视图中的选定项目。
// 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);
}
}
}