I'm new to C#. I'm trying to build an WPF application which takes data from an Excel Sheet and insert into an DataTable
.
The Window will be having multiple textboxes with Search Button. On clicking the Search Button, the Program should search for a value in column ID
that equals with Text in TextBox
, then return all the corresponding row values that gets displayed in each specific non-editable TextBox
.
Since I don't want an actual DataGrid
into the UI, I just created an DataGrid
Object and loaded all the Data. After I used the following code from here:
for (int i = 0; i < dataGrid.Items.Count; i++)
{
DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(i);
TextBlock cellContent = dataGrid.Columns[0].GetCellContent(row) as TextBlock;
if (cellContent != null && cellContent.Text.Equals(textBox1.Text))
{
object item = dataGrid.Items[i];
dataGrid.SelectedItem = item;
dataGrid.ScrollIntoView(item);
row.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
break;
}
}
But the above code doesn't work unless I add an DataGrid
to XAML and fill it up. Most of the solutions I found are requiring me to add it to the XAML. Thought of posting it as a new question. Kindly help me.
PS: I already built this application in VB.NET (It was not so tough) Now I want to move over to C#.