Click here to Skip to main content
15,847,263 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
I have a DataGrid
I fill the DG from a DB
It does fill in a split second so it does fill fast with the Data

But directly after my fill code I have code that gets me the cell info of the first row 3rd column of the DG
Which returns me Null

I feel what is happening is that the DG is just not quite loaded when cell info code runs

I have attached my cell info code to a button and it works fine

I'd love some help please



private void ArtistDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
if (ArtistDataGrid.SelectedIndex >= 0)
var i = ArtistDataGrid.SelectedIndex.ToString();
System.Data.DataRowView lbi = (System.Data.DataRowView)ArtistDataGrid.SelectedValue;
var ArtistName = (lbi.Row[0].ToString());
labelArtistName.Content = ArtistName;
string WhichArtist = ArtistName;

juke_RWPF._VideoMusicjuke_RDataSet1_GroupSongByArtist _VideoMusicjuke_RDataSet1_GroupSongByArtist = ((juke_RWPF._VideoMusicjuke_RDataSet1_GroupSongByArtist)(this.FindResource("_VideoMusicjuke_RDataSet1_GroupSongByArtist")));
// Load data into the table GroupSongsByArtistqry. You can modify this code as needed.
juke_RWPF._VideoMusicjuke_RDataSet1_GroupSongByArtistTableAdapters.GroupSongsByArtistqryTableAdapter _VideoMusicjuke_RDataSet1_GroupSongByArtistGroupSongsByArtistqryTableAdapter = new juke_RWPF._VideoMusicjuke_RDataSet1_GroupSongByArtistTableAdapters.GroupSongsByArtistqryTableAdapter();
_VideoMusicjuke_RDataSet1_GroupSongByArtistGroupSongsByArtistqryTableAdapter.FillBy2(_VideoMusicjuke_RDataSet1_GroupSongByArtist.GroupSongsByArtistqry, WhichArtist);
System.Windows.Data.CollectionViewSource groupSongsByArtistqryViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("groupSongsByArtistqryViewSource")));

string myArtistPic = "";
TextBlock x = SongGroupDataGrid.Columns[2].GetCellContent(SongGroupDataGrid.Items[0]) as TextBlock;
if (x != null)
myArtistPic = x.Text;
string MyString = (x.Text);
char[] MyChar = { 'g', 'p', 'm', '.', ' ' };
string NewString = MyString.TrimEnd(MyChar);
string ArtistPicture = ((NewString) + (".jpg"));
ImageSource imgsr = new BitmapImage(new Uri(ArtistPicture));
PictureBox1.Source = imgsr;
Updated 18-Jun-13 22:11pm
Philip Stuyck 15-Jun-13 9:31am    
I think you will have to show what you have in order for anybody to help.
Clifford Nelson 18-Jun-13 20:38pm    
Just add it to the question with the pre tags to let it look like code. In a comment like this very hard to read.
anthp 19-Jun-13 2:50am    
Hi Clifford
Thanks for you advise i hope this is better
I am not sure about the pre tags



This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900