Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridView Databinding
 

DataGridView Databinding

I have a program which will use many forms set up the same way with a BindingNavigator and DataGridView. I use a dataset, and store the data ina SQL Server database.

There are several bugs in the DataGridView that I have found solutions for, and want to use this modified dataGridView as a base control, along with the BindingNavigator. I put the BindingNavigator and DataGridView on the same UserControl, but am now unsure of how to connect this to my DataSet on the form that inherits this UserControl. If I drag and drop from the Data Sources window, it will create a new DataGridView, which would still have all the bugs in it.

TIA,

Eric

Programming_Eric  Wednesday, February 13, 2008 9:17 PM

Hi Eric,


According to what I understand you have a datagridview in a usercontrol and you are not able to bind the dataset in the derived form to this datagridview.

Make the control in usercontrol available to derived form by making that control public like,


public DataGridView CommonGridView
{
get
{
return _gridView;
}
}

This needs to be written in the base class.

Then the datagridview will be available in the derived class.You can now add the datasource and all by doing something like this,


private void FormatUserGrid()
{
DataView dv = new DataView();
dv.Table = _loginDs.Tables[0];//The dataset _loginDs is assigned to a dataview

DataGridViewTextBoxColumn uname = new DataGridViewTextBoxColumn();
uname.HeaderText = "user";
uname.Name = "username";
uname.DataPropertyName = "username";
dataGridViewUserControl1.CommonGridView.Columns.Add(uname);

//DataGridViewUserControl1 is the UserControl made
dataGridViewUserControl1.CommonGridView.DataSource = dv;
}

To get the events for the datagridview they need to be added as public in the usercontrol and use them at the derived form.

Cheers..

_____________________________
http://techisolutions.blogspot.com/




Annamika  Thursday, February 14, 2008 11:31 AM

I was reading some info on something similiar a few days ago. It was creating a custom control of some sort, i just can't remember what exactly. However i did look at something similar to create a custom progressbar control. If you created a custom control in a class of some sort then you should have ended up with a dll that you can add as a reference to your project and then drag your control to your form. I have a sample to paper that shows how to do this but it is fairly lengthy. If you need i can try to post it here or email it to you but you might be able to figure it out from here.

Jeff - www.SRSoft.us  Thursday, February 14, 2008 12:55 AM

Hi Eric,


According to what I understand you have a datagridview in a usercontrol and you are not able to bind the dataset in the derived form to this datagridview.

Make the control in usercontrol available to derived form by making that control public like,


public DataGridView CommonGridView
{
get
{
return _gridView;
}
}

This needs to be written in the base class.

Then the datagridview will be available in the derived class.You can now add the datasource and all by doing something like this,


private void FormatUserGrid()
{
DataView dv = new DataView();
dv.Table = _loginDs.Tables[0];//The dataset _loginDs is assigned to a dataview

DataGridViewTextBoxColumn uname = new DataGridViewTextBoxColumn();
uname.HeaderText = "user";
uname.Name = "username";
uname.DataPropertyName = "username";
dataGridViewUserControl1.CommonGridView.Columns.Add(uname);

//DataGridViewUserControl1 is the UserControl made
dataGridViewUserControl1.CommonGridView.DataSource = dv;
}

To get the events for the datagridview they need to be added as public in the usercontrol and use them at the derived form.

Cheers..

_____________________________
http://techisolutions.blogspot.com/




Annamika  Thursday, February 14, 2008 11:31 AM

You can use google to search for other answers

Custom Search

More Threads

• Handle a ButtonClick event while a DatagridViewCell is in editmode
• Combobox Selectedvalue problem
• How can i programatically select and focus through all the rows in the DataGrid.
• DataGridView, KeyDown Event
• DataGridView setup problem
• Sending SMTP mail to customer from an Datagrid
• Accessing DataTable rows at design time
• Datagridview - display row vertical
• Dataset Designer. datatable acting strangely
• download files from server in c#