VS2013 を使用して、SQL Server データベースで Windows フォーム アプリケーションを開発しています。
イメージ名を格納するためのデータベース テーブルに列があります。
私のアプリケーションでは、コンピューターから画像を選択し、その画像をアプリケーションの起動パスに保存するボタンを作成します。
private void buttonX1_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "Image only. | *.jpg; *.jpeg; *png; *.gif;";
dlg.InitialDirectory = @"E:\";
dlg.Multiselect = false;
string a = null;
if (dlg.ShowDialog() == DialogResult.OK)
{
string[] tmp = dlg.FileNames;
foreach (string i in tmp)
{
FileInfo fi = new FileInfo(i);
string[] xxx = i.Split('\\');
string des = Application.StartupPath + @"\Images\" + xxx[xxx.Length - 1];
string desfolder = Application.StartupPath + @"\Images\";
imagename = xxx[xxx.Length - 1].ToString();
System.IO.Directory.CreateDirectory(desfolder);
File.Delete(des);
imageuploaded.Image = Image.FromFile(dlg.FileName);
//over.
fi.CopyTo(des);
imageList1.Images.Add(imagename, Image.FromFile(des));
//Process.Start("explorer.exe", desfolder);
}
MessageBox.Show("Thành công ");
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
そのコードは、コンピューターから画像を読み込み、スタートアップ パスの "images" フォルダーに保存し、imagelist1 にも画像を追加します。
その後、イメージ名を「イメージ」列(SQLサーバーデータベース)に挿入するボタンがあります。グリッドにイメージリストを使用するこのコードがあります:
public PrdMan()
{
InitializeComponent();
GridPanel panel = superGridControl1.PrimaryGrid;
GridColumn column = panel.Columns["image"];
column.EditorType = typeof(MyGridImageEditControl);
column.EditorParams = new object[] { imageList1, ImageSizeMode.Zoom };
//superGridControl1.PrimaryGrid.Columns[8].Visible = false;
//superGridControl1.PrimaryGrid.Columns[2].CellStyles = "dd/MM/yyyy";
//styleManager1.ManagerStyle = eStyle.Metro;
//
//this.Location = new Point(0, 0);
//this.Size = Screen.PrimaryScreen.WorkingArea.Size;
}
グリッドをロードするコード:
this.mPhamTableAdapter.Fill(this.beautyMaDataSet.MPham);
this.superGridControl1.PrimaryGrid.DataSource = this.beautyMaDataSet.MPham;
私の問題は次のとおりです。画像をロードしてデータベースの「画像」列に挿入すると、成功し、グリッドに画像が表示されます。しかし、アプリを閉じる (公開後) か、デバッグを停止する (VS で) と、再度開きます (または再度デバッグします)。グリッドに画像が表示されない
画像はまだフォルダにありましたが、
imagelistにはリストに画像がありません:
何が問題なのかわかりません。方法をサポートしてもらえますか:
1/ C# を使用して PC からスタートアップ パスのフォルダーにイメージを追加し、イメージ名を SQL サーバーに保存します (イメージをグリッドにバインドするため)。
2/ 起動パスのフォルダーからイメージをイメージリストにバインドして使用します。
ご支援ありがとうございます。