which is best one for binding data in data grid view ?

Posted by Savari_Arm under WPF on 7/14/2012 | Points: 10 | Views : 3448 | Status : [Member] | Replies : 10
in WPF datagrid view and winforms datagrid view which is best one to read,bind,set the data's . give your point of you. dont use link.




Responses

Posted by: Premalatha on: 7/15/2012 [Member] Starter | Points: 25

Up
0
Down
Controls and Properties
To show the records in DataGridView and insert data into the
Database table in this project I have used following controls:-
a. TextBoxes: Name id="txtname", FatherName id="txtfname",
age id="txtage", emailid id="txtemail, userid id="txtuserid".
b. Button: id="btnInsert" text="Insert".
c. Button: id="btnShow" text="Show Records".
d. DataGridView: id="dgRecords".
NameSpace:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.SqlTypes;


Code Page:
1. Insert Records into DataBase :
private void btnInsert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
try
{

con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\asp.net helper\\Window Project\\19. BindDataGrid\\BindDataGrid\\BindDataGrid\\DataGridView.mdf;Integrated Security=True;User Instance=True";
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "insertRecord";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Clear();
com.Parameters.AddWithValue("@name", txtName.Text.Trim());
com.Parameters.AddWithValue("@fname", txtFname.Text.Trim());
com.Parameters.AddWithValue("@age", txtAge.Text.Trim());
com.Parameters.AddWithValue("@email", txtEmail.Text.Trim());
com.Parameters.AddWithValue("@userid", txtUserid.Text.Trim());
con.Open();
int i = com.ExecuteNonQuery();
if (i > 0)
MessageBox.Show("inserted successfully", "DataGridView");
else
MessageBox.Show("not inserted", "DataGridview");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "DataGridView");
}
finally
{
con.Close();
}
}
2. Show Records in DataGridView Control from DataBase:
private void btnShow_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
try
{

con.ConnectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=D:\\asp.net helper\\Window Project\\19. BindDataGrid\\BindDataGrid\\BindDataGrid\\DataGridView.mdf;Integrated Security=True;User Instance=True"; ;
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "showRecord";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Clear();
con.Open();
SqlDataReader dr = com.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
dgRecords.DataSource = dt;
setColumnWidth();
showColumn();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "DataGridView");
}
finally
{
con.Close();
}
}
3. Set the Column Width in DataGridView Control:
public void setColumnWidth()
{
dgRecords.Columns[1].Width = 100;
dgRecords.Columns[4].Width = 200;
dgRecords.Columns[5].Width = 200;
}
4. Hide particular Column in DataGridView Control :
public void showColumn()
{
dgRecords.Columns[0].Visible = false;
dgRecords.Columns[2].Visible = false;
dgRecords.Columns[3].Visible = false;

}
http://www.codeproject.com/Articles/30905/WPF-DataGrid-Practical-Examples

Premalatha
Software Engineer

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savari_Arm on: 7/15/2012 [Member] Starter | Points: 25

Up
0
Down
what a great answer thank you. but
i know that......... my question is which is the best wpf datagrid Vs winform datagird.

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premalatha on: 7/15/2012 [Member] Starter | Points: 25

Up
0
Down
For that i given a link

Premalatha
Software Engineer

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savari_Arm on: 7/16/2012 [Member] Starter | Points: 25

Up
0
Down
i am also see that but... i am confused in that statement in winforms datagridview we can get the row details and cell information like that

for(int i=0;i<datagridview1.rows.count-1;i++
{

string a=datagridview1.Rows[1].cells[0].values.Tostring();
string b=datagridview1.Rows[1].cells[1].values.Tostring();
}

instead of WPF datagrid how to we get the row details any one can help me?...

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dotnetrajanikanth on: 7/16/2012 [Member] Starter | Points: 25

Up
0
Down
http://stackoverflow.com/questions/4613394/wpf-datagrid-vs-windows-forms-datagridview

____________
www.flickr.com/photos/psdesigner/

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 7/16/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
hi Guys

It seems like none of you answered the question as requested.

The Question is

in WPF datagrid view and winforms datagrid view which is best one to read,bind,set the data's . give your point of you. dont use link.


You started sending codes and Links.

To Answer the question the user asked

Answer

Booth of them are easy to Bind, Update data , but the easiest is WPF because of the Binding feature that you can use when you use MVVM , the Binding is clean and easy.


Thank you for posting at Dotnetfunda
[Administrator]

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Premalatha on: 7/16/2012 [Member] Starter | Points: 25

Up
0
Down
You can use datareader
SqlDataReader dr=null;
cmd.commandText="";
dr=cmd.ExcecuteReader();
while(dr.Read())
{
string a=datagridview1.Rows[1].cells[0].values.Tostring();
string b=datagridview1.Rows[1].cells[1].values.Tostring();

}


Premalatha
Software Engineer

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Savari_Arm on: 7/16/2012 [Member] Starter | Points: 25

Up
0
Down
hello understand my need !... i want this same action (read the values from Datagridview) in WPF Datagridview.....


Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: GSM_GSV on: 7/16/2012 [Member] Starter | Points: 25

Up
0
Down
Performance wise: winform is best
UI feature wise: WPF is best

Also you can think of using WPF Performance Suite
http://msdn.microsoft.com/en-us/library/aa969767.aspx#installing_the_wpf_performance_suite

Overall, I mean to say WPF is best

---------------------------------------
Live the life you've dreamed

Regards
MADHU

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Calvert on: 7/17/2012 [Member] Starter | Points: 25

Up
0
Down
WPF Data Grid much more faster, I think. But when I try to use WPF Data Grid for big amount of data (a lot of columns (about 40-50 and rows with styles it working slow horizontal scrolling. Data Grid from 3rd party controls working much better I use Infragistics Xam Data Grid.
http://www.dapfor.com/en/net-suite/net-grid/tutorial/data-types

Savari_Arm, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response