Click here to Skip to main content
16,020,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir,


When I write that line the error is as shown below

Error 1 Cannot implicitly convert type 'object' to 'System.Windows.Forms.DataGridView'. An explicit conversion exists (are you missing a cast?) D:\HR Suite\HR Suite(4-1)\WpfApplication1\WpfApplication1\State.xaml.cs 65 61 WpfApplication1

Sir,
Actually I am using wpf toolkit datagrid

Pls help me

Advance thanks sir
Posted
Updated 12-Jan-10 18:25pm
v2

wrote:
System.Windows.Forms.DataGridView statedg = this.FindName("gridView")


In the xaml, is your datagrid calld 'gridView'? If not, this is the cause of your error.
 
Share this answer
 
private void Add_Click(object sender, RoutedEventArgs e)
{

try
{

SqlCommand cmd = new SqlCommand();
String str = "insert into State(Code,Name)values ('" + this.txtstatecode.Text + "','" + this.txtstatename.Text + "')";
cmd.CommandText = str;
cmd.Connection = conn;
cmd.ExecuteNonQuery();
System.Windows.MessageBox.Show("Data Inserted Successfully");
DataTable dt = new DataTable();

String str1 = "select code,name from State";
//cmd.CommandText = str1;
cmd.Connection = conn;

cmd.CommandType = CommandType.Text;
cmd.CommandText = str1;
//DataSet ds = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter(cmd);

SqlCommandBuilder cb = new SqlCommandBuilder(adp);
adp.Fill(ds,"State");
bs.DataSource = ds.Tables["State"];

statedg5.ItemsSource = bs;
}
catch (Exception e1)
{
System.Windows.MessageBox.Show(e1.Message);
}
finally
{
conn.Close();
}

}





I got answer when I assigned ItemSource instead of DataSource


Thank You
 
Share this answer
 
That you asked this three times is intolerably rude, esp when the issue was one of basic understanding of C#. Perhaps you should buy a book and read it.
 
Share this answer
 

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