filter & datagrid

S

sg

Hi

I'm starting programming in visual studio and c# and i have a problem
with filtering datagrid. I build form with datagrid and i see data from
database. I find in microsoft web page information how to create
filtering data grid but this doesn't work. What I must change? My form code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication10
{
public partial class Form1 : Form
{


public Form1()
{
InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'minicrmDataSet1.adresy' table. You can move, or remove it, as needed.
this.adresyTableAdapter1.Fill(this.minicrmDataSet1.adresy);


}

//from microsoft web page
private void MakeDataView()
{



DataView dv = new DataView();

dv.Table = minicrmDataSet1.Tables["adresy"];
dv.AllowDelete = true;
dv.AllowEdit = true;
dv.AllowNew = true;
dv.RowFilter = "imie = 'Berlin'";
dv.RowStateFilter = DataViewRowState.ModifiedCurrent;
dv.Sort = "imie DESC";

// Simple bind to a TextBox control
Text1.DataBindings.Add("Text", dv, "imie");
}
//

}
}

Thank you in advance for your help

Sebastian
 
B

Bart Mermuys

Hi,

sg said:
Hi

I'm starting programming in visual studio and c# and i have a problem with
filtering datagrid. I build form with datagrid and i see data from
database. I find in microsoft web page information how to create filtering
data grid but this doesn't work. What I must change? My form code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication10
{
public partial class Form1 : Form
{


public Form1()
{
InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the
'minicrmDataSet1.adresy' table. You can move, or remove it, as needed.
this.adresyTableAdapter1.Fill(this.minicrmDataSet1.adresy);


}

//from microsoft web page
private void MakeDataView()
{

DataView dv = new DataView();

I don't see you assign this new DataView to something and instead of
creating a new one, you can use the one BindingSource already uses:

DataView dv = (DataView)this.adresyBindingSource.List;

Any filtering on that DataView should be visible in the grid.


HTH,
Greetings
dv.Table = minicrmDataSet1.Tables["adresy"];
dv.AllowDelete = true;
dv.AllowEdit = true;
dv.AllowNew = true;
dv.RowFilter = "imie = 'Berlin'";
dv.RowStateFilter = DataViewRowState.ModifiedCurrent;
dv.Sort = "imie DESC";

// Simple bind to a TextBox control
Text1.DataBindings.Add("Text", dv, "imie");
}
//

}
}

Thank you in advance for your help

Sebastian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top