コントロールパネルのインターネットオプションで、プロキシを設定してある場合でも、WinHTTPのプロキシが設定されていないといけないらしい。
そこで、インターネットオプションに設定されているプロキシの設定内容を、WinHTTPのプロキシに反映させるため、次のコマンドを実行する。
proxycfg -u
ちゃんと設定されたか確認するには、proxycfg
と、引数なしで実行する。WinHTTPのプロキシ設定を元に戻すには、次のコマンドを実行する。
proxycfg -d
kkino90hの技術メモです。
proxycfg -u
ちゃんと設定されたか確認するには、proxycfg
と、引数なしで実行する。proxycfg -d

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataGridViewTest
{
public partial class Form1 : Form
{
private DataTable m_table;
public Form1()
{
InitializeComponent();
// データテーブル生成
m_table = new DataTable();
m_table.Columns.Add(new DataColumn("id" , typeof(int)));
m_table.Columns.Add(new DataColumn("value", typeof(int)));
m_table.PrimaryKey = new DataColumn[] { m_table.Columns["id"] };
m_table.Columns["id"].AutoIncrement = true;
m_table.Columns["id"].AutoIncrementSeed = 1;
m_table.Columns["id"].AutoIncrementStep = 1;
}
private void Form1_Load(object sender, EventArgs e)
{
// データテーブルをDataGridViewにバインド
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = m_table;
// バックグラウンド処理開始
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
System.Random rnd = new Random();
// データテーブルに1000行のデータを追加する
for (int index = 0; index < 1000; index++)
{
DataRow newRow = m_table.NewRow();
newRow["value"] = rnd.Next(100);
m_table.Rows.Add(newRow);
}
}
}
}
コンストラクタで、DataTableを生成しています。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataGridViewTest
{
public partial class Form1 : Form
{
private DataTable m_table;
public Form1()
{
InitializeComponent();
// データテーブル生成
m_table = new DataTable();
m_table.Columns.Add(new DataColumn("id" , typeof(int)));
m_table.Columns.Add(new DataColumn("value", typeof(int)));
m_table.PrimaryKey = new DataColumn[] { m_table.Columns["id"] };
m_table.Columns["id"].AutoIncrement = true;
m_table.Columns["id"].AutoIncrementSeed = 1;
m_table.Columns["id"].AutoIncrementStep = 1;
}
private void Form1_Load(object sender, EventArgs e)
{
// データテーブルをDataGridViewにバインド
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = m_table;
// グリッドのスクロールバーを一旦なしにする
dataGridView1.ScrollBars = ScrollBars.None;
// バックグラウンド処理開始
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
System.Random rnd = new Random();
// データテーブルに1000行のデータを追加する
for (int index = 0; index < 1000; index++)
{
DataRow newRow = m_table.NewRow();
newRow["value"] = rnd.Next(100);
m_table.Rows.Add(newRow);
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// グリッドのスクロールバーを元に戻す
dataGridView1.ScrollBars = ScrollBars.Both;
}
}
}
こうすると、フリーズせずに動きました。
set serverout on;
とする必要がある。set serverout on size 1000000;
のようにバッファサイズを指定する。
* {
}
@font-face {
font-family: "MS PGothic";
src: local("メイリオ");
}
@font-face {
font-family: "MS Pゴシック";
src: local("メイリオ");
}
@font-face {
font-family: "arial";
src: local("メイリオ");
}
という記述を追加して、保存(文字コードはUTF-8 BOM無)します。
そうすると、次のようなフォームができます。using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
namespace WPFDataGridSample
{
///
/// MainWindow.xaml の相互作用ロジック
///
public partial class MainWindow : Window
{
//-------------------------------------------------------------------- メンバ変数
private DataTable m_table_mst_category; // カテゴリマスタテーブル
private DataTable m_table_mst_item; // 商品マスタテーブル
//-------------------------------------------------------------------- コンストラクタ
public MainWindow()
{
InitializeComponent();
// テーブルの初期化
try
{
InitTables();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, Title, MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
// グリッドにバインド
dataGrid1.DataContext = m_table_mst_item;
col_category_id.ItemsSource = m_table_mst_category.DefaultView; // カテゴリ列
}
//-------------------------------------------------------------------- メンバ関数
///
/// テーブルの初期化
///
private void InitTables()
{
// カテゴリマスタテーブルの生成
m_table_mst_category = new DataTable("mst_category");
m_table_mst_category.Columns.Add(new DataColumn("category_id" , typeof(int) )); // カテゴリID
m_table_mst_category.Columns.Add(new DataColumn("category_name", typeof(string) )); // カテゴリ名
m_table_mst_category.Columns.Add(new DataColumn("create_date" , typeof(DateTime))); // 作成日時
m_table_mst_category.Columns.Add(new DataColumn("update_date" , typeof(DateTime))); // 更新日時
m_table_mst_category.PrimaryKey = new DataColumn[] { m_table_mst_category.Columns["category_id"] }; // プライマリキーの設定
m_table_mst_category.Columns["category_name"].Unique = true; // ユニークキーの設定
m_table_mst_category.Columns["category_id"].AutoIncrement = true; // 自動採番の設定
m_table_mst_category.Columns["category_id"].AutoIncrementSeed = 1; // 自動採番は1から始まり
m_table_mst_category.Columns["category_id"].AutoIncrementStep = 1; // 自動採番は1ずつ増加
m_table_mst_category.TableNewRow += new DataTableNewRowEventHandler(m_table_mst_category_TableNewRow); // TableNewRowイベントの追加
// サンプルデータ追加
foreach (var category_name in new string[] { "液晶テレビ", "ブルーレイレコーダ" })
{
DataRow newRow = m_table_mst_category.NewRow();
newRow["category_name"] = category_name;
m_table_mst_category.Rows.Add(newRow);
}
// 商品マスタテーブルの生成
m_table_mst_item = new DataTable("mst_item");
m_table_mst_item.Columns.Add(new DataColumn("item_id" , typeof(int) )); // 商品ID
m_table_mst_item.Columns.Add(new DataColumn("item_name" , typeof(string) )); // 商品名
m_table_mst_item.Columns.Add(new DataColumn("category_id", typeof(int) )); // カテゴリID
m_table_mst_item.Columns.Add(new DataColumn("status" , typeof(bool) )); // ステータス
m_table_mst_item.Columns.Add(new DataColumn("create_date", typeof(DateTime))); // 作成日時
m_table_mst_item.Columns.Add(new DataColumn("update_date", typeof(DateTime))); // 更新日時
m_table_mst_item.PrimaryKey = new DataColumn[] { m_table_mst_item.Columns["item_id"] }; // プライマリキーの設定
m_table_mst_item.Columns["item_name"].Unique = true; // ユニークキーの設定
m_table_mst_item.Columns["item_id"].AutoIncrement = true; // 自動採番の設定
m_table_mst_item.Columns["item_id"].AutoIncrementSeed = 1; // 自動採番は1から始まり
m_table_mst_item.Columns["item_id"].AutoIncrementStep = 1; // 自動採番は1ずつ増加
m_table_mst_item.TableNewRow += new DataTableNewRowEventHandler(m_table_mst_item_TableNewRow); // TableNewRowイベントの追加
// サンプルデータ追加
DataRow newRowItem;
newRowItem = m_table_mst_item.NewRow();
newRowItem["item_name"] = "LED REGZA ZG1";
newRowItem["category_id"] = m_table_mst_category.Select("category_name='液晶テレビ'")[0]["category_id"];
m_table_mst_item.Rows.Add(newRowItem);
newRowItem = m_table_mst_item.NewRow();
newRowItem["item_name"] = "RD-X10";
newRowItem["category_id"] = m_table_mst_category.Select("category_name='ブルーレイレコーダ'")[0]["category_id"];
m_table_mst_item.Rows.Add(newRowItem);
}
//-------------------------------------------------------------------- イベント関数
// カテゴリマスタのTableNewRowイベント
private void m_table_mst_category_TableNewRow(object sender, DataTableNewRowEventArgs e)
{
e.Row["create_date"] = DateTime.Now;
e.Row["update_date"] = DateTime.Now;
}
// 商品マスタのTableNewRowイベント
private void m_table_mst_item_TableNewRow(object sender, DataTableNewRowEventArgs e)
{
e.Row["status" ] = true;
e.Row["create_date"] = DateTime.Now;
e.Row["update_date"] = DateTime.Now;
}
}
}
メンバ変数に、m_table_mst_categoryとm_table_mst_itemというDataTableを用意して、InitTables関数で各テーブルを生成しサンプルデータを作成しています。 // グリッドにバインド
dataGrid1.DataContext = m_table_mst_item;
col_category_id.ItemsSource = m_table_mst_category.DefaultView; // カテゴリ列の部分で、 dataGrid1.DataContext = m_table_mst_item;で、DataGridに商品マスタのDataTableをバインドしています。 col_category_id.ItemsSource = m_table_mst_category.DefaultView;で、col_category_idにバインドしています。さらにMainWindow.xamlの中でカテゴリ列は としているため、カテゴリマスタテーブル(m_table_mst_category)のcategory_idが選択値、category_nameが表示値となります。 col_category_id.ItemsSource = m_table_mst_category.Rows;とすると、カテゴリ列が空白になって正しく表示されません。ただ入力するときのコンボボックスのドロップダウンする行数はカテゴリマスタの件数と一致しているので、カテゴリ列とカテゴリマスタのDataTableとのバインドはうまくいっていると思いますが、表示がうまくいかないようです(DataGridのバグなのか制約なのかよくわかりません)。