Hello!
I'm sorry for my english ;)
I want to download images in a grid from a database, edit them and save the result back to base.
I have a database (SQLite) that has a table with images.
I use the grid as follows:
Code when loading windows
When the window boot - displays a grid with pictures. All works well.
I can make changes in the "Note" and save the changes to the database.
Saving changes is as follows:
I'm trying to change the picture in the grid as follows:
No changes (not in the grid, not in the database) does not occur. The grid displays the old picture.
Tell me what am I doing wrong?
How to change the image with the grid and in the database?
I'm sorry for my english ;)
I want to download images in a grid from a database, edit them and save the result back to base.
I have a database (SQLite) that has a table with images.
I use the grid as follows:
<
Window.Resources
>
<
my:GoodsInStoreDataSet
x:Key
=
"dsMy"
/>
<
CollectionViewSource
x:Key
=
"vs_t_test"
Source
=
"{Binding Path=t_test, Source={StaticResource dsMy}}"
/>
</
Window.Resources
>
<
Grid
DataContext
=
"{StaticResource vs_t_test}"
>
<
telerik:RadGridView
ItemsSource
=
"{Binding}"
Name
=
"rdGrid"
AutoGenerateColumns
=
"False"
MouseDoubleClick
=
"rdGrid_MouseDoubleClick"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding ID}"
Header
=
"ID"
/>
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding NOTE}"
Header
=
"Note"
/>
<
telerik:GridViewImageColumn
DataMemberBinding
=
"{Binding Picture}"
Header
=
"Pic"
MinWidth
=
"100"
ImageStretch
=
"Fill"
MaxWidth
=
"100"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
</
Grid
>
Code when loading windows
private
void
Window_Loaded(
object
sender, RoutedEventArgs e)
{
GoodsInStore.GoodsInStoreDataSet dsGIS = ((GoodsInStore.GoodsInStoreDataSet)(
this
.FindResource(
"dsMy"
)));
GoodsInStore.GoodsInStoreDataSetTableAdapters.t_testTableAdapter ta_t_test =
new
GoodsInStore.GoodsInStoreDataSetTableAdapters.t_testTableAdapter();
ta_t_test.Fill(dsGIS.t_test);
System.Windows.Data.CollectionViewSource vs_t_test = ((System.Windows.Data.CollectionViewSource)(
this
.FindResource(
"vs_t_test"
)));
vs_t_test.View.MoveCurrentToFirst();
}
When the window boot - displays a grid with pictures. All works well.
I can make changes in the "Note" and save the changes to the database.
Saving changes is as follows:
private
void
SaveButton_Click(
object
sender, RoutedEventArgs e)
{
GoodsInStore.GoodsInStoreDataSet dsGIS = ((GoodsInStore.GoodsInStoreDataSet)(
this
.FindResource(
"dsMy"
)));
GoodsInStore.GoodsInStoreDataSetTableAdapters.t_testTableAdapter ta_t_test =
new
GoodsInStore.GoodsInStoreDataSetTableAdapters.t_testTableAdapter();
ta_t_test.Update(dsGIS.t_test);
}
I'm trying to change the picture in the grid as follows:
private
void
OnCellDoubleClick(
object
sender, RadRoutedEventArgs args)
{
GridViewCellBase cell = args.OriginalSource
as
GridViewCellBase;
if
(cell !=
null
&& cell.Column.UniqueName ==
"Picture"
)
{
Microsoft.Win32.OpenFileDialog dlg =
new
Microsoft.Win32.OpenFileDialog();
dlg.DefaultExt =
".jpg"
;
dlg.Filter =
"Jpeg pictures (.jpg)|*.jpg"
;
Nullable<
bool
> result = dlg.ShowDialog();
if
(result ==
true
)
{
string
filename = dlg.FileName;
BitmapImage myBitmapImage =
new
BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource =
new
Uri(filename, UriKind.RelativeOrAbsolute);
myBitmapImage.EndInit();
rdGrid.CurrentCell.Value = myBitmapImage;
}
}
}
No changes (not in the grid, not in the database) does not occur. The grid displays the old picture.
Tell me what am I doing wrong?
How to change the image with the grid and in the database?