Home>
I want to get the CSV data and execute the work, but I want to execute it after checking only the columns that have the title, price, and image URL data once.
Therefore, I want to use DataGrid to display only the specified columns.
I implemented the following code in the button, but I do not understand after this.
Development environment
Visual Studio 2019 version 16.5.4
.NET Framework Version 4.8.03752
is.
CSV image
title | price | Explanation | Year of issue | image |
---|---|---|---|---|
Title 1 | Price 1 | Explanation 1 | Publication year 1 | Image 1 |
Title 2 | Price 2 | Explanation 1 | Publication year 2 | Image 2 |
.
.
.
↓ (I want to display only the columns marked with * in the DataGrid)
title※ | price※ | Explanation | Year of issue | image※ |
---|---|---|---|---|
Title 1 * | Price 1 * | Explanation 1 | Publication year 1 | Image 1 * |
Title 2 * | Price 2 * | Explanation 1 | Publication year 2 | Image 2 * |
.
.
.
private void OpenFileDialogforCsv_Click (object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog ();
if (ofd.ShowDialog () == true)
{
string content = File.ReadAllText (ofd.FileName, Encoding.GetEncoding ("Shift_JIS"));
DataTable dt = GetCsvDataTable (content);
this.dataGrid.ItemsSource = dt.DefaultView;
}
}
private DataTable GetCsvDataTable (string content) {}
xaml looks like this.
<StackPanel>
<Button Content = "Reference"
Height = "40" Width = "100" Margin = "10"
FontSize = "20" FontWeight = "Bold" Background = "SkyBlue" />
<DataGrid Grid.Row = "1" Name = "dataGrid" Height = "500" />
<Button Content = "Work execution"
Height = "50" Width = "200" Margin = "25" Background = "Orange"
FontSize = "25" FontWeight = "Bold" />
</StackPanel>
-
Answer # 1
Related articles
- c # - i want to display an object when the specified number of taps is reached
- c # - in the data grid view, i want to center any column header position and left justify the cell position of that column
- c # - i want to display my form as new after sleeping for a few seconds
- c # - i want to display an image set in a two-dimensional array with wpf
- c # - i want to get 5 items in unity and display the clear screen
- css3 - if background: linear-gradient is specified by css, the display will change when using iphone
- [sql oracle] how to display the specified character when the cell is blank
- c # - i want to get and display the values of multiple tables with mvc
- i don't know how to randomly extract images in c # and display them in picturebox
- c # - cannot be specified as a relative path to openfiledialoginitialdirectory
- javascript - how to get the src of the clicked img and display the src of the obtained img in the specified location (when there
- c # - processing to display subwindows in parallel processing
- sql - when you want to display multiple values in one column
- get audio in c # and display waveform
- i want itextsharp to display table borders twice (c #)
- python - i want to use if to return the specified keyword in the new column when the values in the two columns of the data fra
- c # - batch display of hidden child/grandchild/great-grandchild objects
- css - when i specified display: flex;for img, width did not work
- html - even if display: inline-block;is specified, it is not reflected
- c # - about unity ads test ad display
Related questions
- c # - i want to change the background color and text color of any day with the wpf calendar control
- c # - i want to disable button when textbox is blank in reactiveproperty
- c # - i want to read an xml file and display it on the datagrid
- c # - i want to know the intent of mvvm "viewmodel must not know view"
- c # - i want to get the content of the child element label in the wpf button
- i want to pass an argument to mainwindow () and execute it [wpf net framework c #]
- c # - [wpf] how to play an animation only when the code-behind conditions are met
- c # - about wpf x button control
- c # - [wpf] how to put a changing value in the binding path
- c # - how to specify the argument systemwindowsuielement as a string
DataGrid
Is an example that corresponds.If the columns to be displayed or hidden are fixed, it is quick to specify the columns with xaml.
If you want to switch between display and non-display, it is more convenient to change it from the code.
DataGrid.AutoGeneratingColumn Event (System.Windows.Controls) | Microsoft Docs
You can use this one.
I will omit "datatable column deletion" because it is more complicated.
As for "wpf datagrid column hidden", there are some elaborate bindings, but simple ones are surprising.