This is a migrated thread and some comments may be shown as answers.

Refreshing GridView with database in WPF

6 Answers 274 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Maarten
Top achievements
Rank 1
Maarten asked on 12 Jul 2011, 01:51 PM
Hello Telerik team,

I am using your radGirdView for viewing some of my records in my database.
When I add a record in my database, the gridview does not refresh.

I am new to WPF and it is just a simple basic program.

Thanks in advance!
Maarten
public void refreshList()
        {
            MySqlConnection conn = new MySqlConnection(connString);
            personList.Clear();
            using (conn)
            {
                String sql = "SELECT * FROM personeel ORDER BY Naam;";
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                conn.Open();
                MySqlDataReader reader = cmd.ExecuteReader();
                StringBuilder htmlStr = new StringBuilder("");
 
                while (reader.Read())
                {
                    String Naam = htmlStr.Append(reader["Naam"]).ToString();
                    htmlStr.Clear();
                    String Voornaam = htmlStr.Append(reader["Voornaam"]).ToString();
                    htmlStr.Clear();
                    String Gsm = htmlStr.Append("0" + reader["GSM"]).ToString();
                    htmlStr.Clear();
 
                    personList.Add(new Person(Voornaam, Naam, Gsm));
                }
                conn.Close();
            }
            //gridView1 = new Telerik.Windows.Controls.RadGridView();
             
            gridView1.ItemsSource = personList;
             
            //CollectionViewSource.GetDefaultView(gridView1.ItemsSource).Refresh();
             
        }

6 Answers, 1 is accepted

Sort by
0
Siingh
Top achievements
Rank 2
answered on 13 Jul 2011, 02:27 AM
Since you are using database to bind records i would suggest you to rebind again with same example, so you put that code in one routine and call this routine again after grid operation, if you are using visualization then it will be very quick to load also.


in you XAML make sure you are using like this

DataMemberBinding="{Binding [Naam], Mode=TwoWay}"

this will help you to achieve that.


Kind Regards:
0
Maarten
Top achievements
Rank 1
answered on 13 Jul 2011, 09:05 AM
Dear Siingh,

Thank you so much for your reply!

But the only thing I get when i try to make my columns myself I only get this:

<telerik:RadGridView x:Name="gridView1" Grid.Row="2" Width="295" Margin="4,1,0,4"
                             AutoGenerateColumns="False" ItemsSource="{Binding}"
                             RowIndicatorVisibility="Collapsed" IsFilteringAllowed="False"
                             AllowDrop="False" CanUserFreezeColumns="False" CanUserReorderColumns="False"
                             CanUserInsertRows="False" ShowGroupPanel="False" ShowColumnFooters="True"
                             AreRowDetailsFrozen="True" IsReadOnly="True"
                             Control.MouseDoubleClick="ListView_MouseDoubleClick" DataMember="{Binding Naam, Mode=TwoWay}">
            <telerik:GridViewColumn.RadGridView></telerik:GridViewColumn.RadGridView>
             
        </telerik:RadGridView>

This gives an error. There is no DataMemberBinding in the list of intellisense.

Thanks in advance!
Maarten
0
Maarten
Top achievements
Rank 1
answered on 13 Jul 2011, 09:07 AM
Sorry i've been stupid, it's ok now for making my columns!
0
Maarten
Top achievements
Rank 1
answered on 13 Jul 2011, 09:18 AM
I did it like you said Siingh, but it still doesn't refresh.

Any other ideas?

Thanks in advance!

Maarten
0
Siingh
Top achievements
Rank 2
answered on 13 Jul 2011, 09:28 AM
Hi See this is what i used when i need to refresh the grid.

Dim dtTable As New DataTable()
           dtTable.Clear()
           boores = objSync.RawTimeSheet_GetAll(dtTable, expobj)
           If boores = False Then
               ShowError(expobj)
           End If
           GridDaily.ItemsSource = dtTable
           GridDaily.Rebind()


use GridView.Rebind() to rebind the item source from datatable or datasource.

Try this let me know if this helps you.
0
Maarten
Top achievements
Rank 1
answered on 13 Jul 2011, 10:35 AM
Sorry, this does not help me.
It just won't refresh.

Edit: when I link the refreshList() to a button, it will work but i want it to refresh automatically when i add someone to the list.
Tags
GridView
Asked by
Maarten
Top achievements
Rank 1
Answers by
Siingh
Top achievements
Rank 2
Maarten
Top achievements
Rank 1
Share this question
or