What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 20925 |  Welcome, Guest!   Register  Login
 Home > Forums > WPF > which is best one for binding data in data grid view ? ...
Savari_Arm

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

Replies: 10 | Posted by: Savari_Arm on 7/14/2012 | Category: WPF Forums | Views: 1311 | Status: [Member] | Points: 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.


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Premalatha
Premalatha  
Posted on: 7/15/2012 1:00:13 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Savari_Arm
Savari_Arm  
Posted on: 7/15/2012 2:54:34 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Premalatha
Premalatha  
Posted on: 7/15/2012 5:39:48 AM
Level: Starter | Status: [Member] | Points: 25

For that i given a link

Premalatha
Software Engineer

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

Savari_Arm
Savari_Arm  
Posted on: 7/16/2012 12:38:44 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Dotnetrajanikanth
Dotnetrajanikanth  
Posted on: 7/16/2012 1:34:25 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Vuyiswamb
Vuyiswamb  
Posted on: 7/16/2012 3:00:16 AM
Level: NotApplicable | Status: [Member] [MVP] [Administrator] | Points: 25

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. | Reply | Alert Moderator 

Premalatha
Premalatha  
Posted on: 7/16/2012 5:25:03 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Savari_Arm
Savari_Arm  
Posted on: 7/16/2012 7:13:09 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

GSM_GSV
GSM_GSV  
Posted on: 7/16/2012 7:31:51 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Calvert
Calvert  
Posted on: 7/17/2012 1:28:08 AM
Level: Starter | Status: [Member] | Points: 25

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. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 6:15:42 AM