Click to See Complete Forum and Search --> : Help formating & filtering dgv or DS
Crash893
Jul 15th, 2007, 02:55 PM
Hi all
I am passing a dataset to a dgv and i need to add a column to the DGV that is not in the dataset but is made from info in the dataset
example
col1
12
34
14
47
col0(<-add) col1
hyperlink12 12
hyperlink34 34
hyperlink14 14
hyperlink47 47
I also want to go through certain column's and remove some text
companyname/user
companyname/user2
to just:
user
user2
then the last thing i want to do is filter feilds by date or other criteria
So my question is
should i do this at the data table level or should i do it at the data grid level because i'm not sure i want to mess with the original data just yet
then depending on where i edit the data does anyone have a good example that i could look at to point me in the right direction?
jmcilhinney
Jul 16th, 2007, 02:11 AM
http://msdn2.microsoft.com/en-us/library/zkatshfa(VS.80).aspx
Crash893
Jul 16th, 2007, 01:29 PM
Just incase anyone wants to see
private void CreateUnboundButtonColumn()
{
// Initialize the button column.
DataGridViewButtonColumn buttonColumn =
new DataGridViewButtonColumn();
buttonColumn.Name = "Details";
buttonColumn.HeaderText = "Details";
buttonColumn.Text = "View Details";
// Use the Text property for the button text for all cells rather
// than using each cell's value as the text for its own button.
buttonColumn.UseColumnTextForButtonValue = true;
// Add the button column to the control.
dataGridView1.Columns.Insert(1, buttonColumn);
}
Crash893
Jul 16th, 2007, 02:01 PM
3 left over questions
1) what is the event for when i click on one of the new buttons i have created
here is what i have but i dont think im even close
private void dataGridView1_CellClick(object sender,DataGridViewCellEventArgs e)
{
MessageBox.Show("hi you pushed a button");
}
2) to edit and format the data do i do it at the datagridview level or at the Dataset/datatable level?
3) Probably related to 2 but how is filtering done with DGV?
jmcilhinney
Jul 16th, 2007, 08:17 PM
1. CellContentClick.
2. You should bind your data to a BindingSource and then bind that to the control(s). All manipulation of data in code should then be done via the BindingSource.
3. Set the Filter property of the BindingSource. If you don't use a BindingSource then you'd set the DefaultView.RowFilter property of the DataTable but I can't recommend strongly enough that you use a BindingSource.
Crash893
Jul 17th, 2007, 12:20 PM
Here is what i go so far it seems to be working pretty well
but i still need to test with a few filters strung together (i will Google it)
BindingSource gridinfo = new BindingSource();
private void button2_Click(object sender, EventArgs e)
{
//create new Dataset named DS
DataSet DS = new DataSet();
// Query string that we can Manupulate later
string query = "SELECT gci_requests.id, gci_requests.ref_num, gci_requests.summary, gci_requests.description, gci_requests.open_date, gci_requests.last_modified_date, gci_requests.close_date, gci_requests.resolve_date, gci_requests.status, gci_requests.rootcause, gci_requests.priority, gci_requests.urgency, gci_requests.problem, gci_requests.type, gci_requests.category_name, gci_requests.assignee_adaccount, gci_requests.reportedby_adaccount, gci_requests.customer_adaccount, gci_requests.group_name FROM mdb_rpt.dbo.gci_requests gci_requests WHERE gci_requests.group_name='" + comboBox1.Text + "'";
//sending Dataset , query and tablename to the sub TEST
Test(query, DS, "gci_requests");
//binding the Dataset to the binding source
gridinfo.DataSource = DS;
gridinfo.DataMember = "gci_requests";
//useing the binding source to populate the datagridview
dataGridView1.DataSource = gridinfo;
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("USAT-Publishing Solutions");
comboBox1.Items.Add("USAT-Operations");
comboBox1.Items.Add("USAT-Desktop");
comboBox1.Text = "USAT-Publishing Solutions";
comboBox2.Items.Add("502212");
comboBox2.Items.Add("502213");
comboBox2.Items.Add("502214");
comboBox2.Items.Add("502215");
comboBox2.Items.Add("502216");
comboBox2.Items.Add("");
comboBox2.Text = "";
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox2.Text != "")
{
gridinfo.Filter = "rootcause = '" + comboBox2.Text + "'";
}
else
{
gridinfo.Filter = "";
}
}
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.