0

I am using datagridview (not datagrid) in my wpf application and i use this code to call it in my Window

<Window x:Class="TestHosting.MainWindow"
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="440.132" Width="521.053">
<Grid>

    <WindowsFormsHost Margin="20,20,130,142">
        <wf:DataGridView x:Name="dgv">

            <wf:DataGridView.Columns>
                <wf:DataGridViewColumn Name="column1" HeaderText="Col l" />
                <wf:DataGridViewColumn Name="column2" HeaderText="Col 2"/>
                <wf:DataGridViewColumn Name="column3" HeaderText="Col 3"/>
            </wf:DataGridView.Columns>

        </wf:DataGridView>
    </WindowsFormsHost>

and the problem is that an error says that "At Least on of the datagridview controls' columns has no cell template."

how should I fix this error ?

7
  • 1
    Possible duplicate of stackoverflow.com/questions/8456826/… Commented Nov 14, 2014 at 20:38
  • forget winforms, it's totally useless. What do you want that for? Commented Nov 14, 2014 at 22:00
  • @HighCore why winforms is useless, can you explain please? Commented Nov 14, 2014 at 22:05
  • @Fabio because it's inferior, requires more code to achieve less, and whatever you want can be done in WPF just fine, without resorting to a bunch of ridiculous "owner draw" hacks. Commented Nov 14, 2014 at 22:13
  • @HighCore, sorry, I forget, we already discussed that before - I know your point of view :) Commented Nov 15, 2014 at 4:55

1 Answer 1

3

You could use DataGrid, instead of DataGridView

SqlDataAdapter da = new SqlDataAdapter("Select * from Table", con);
                DataTable dt = new DataTable("Call Reciept");
                da.Fill(dt);
                DataGrid dg = new DataGrid();
                dg.ItemsSource = dt.DefaultView;
Sign up to request clarification or add additional context in comments.

2 Comments

Except that DataGrid is very difficult to use in comparison
@rolls coming from WPF DGV is way harder

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.