Need Advice

G

Guest

Hi,

I'm looking for a way to do something, and i need help on finding the best
way to do it.
I've one Form that contains a dataGrid, and one of the buttons in that form,
opens another Form which contains dataGrid that shows list of Headers (each
header represnt a Invoice which was made in the first form in the past), the
first column is a checkbox column, and what i need to do is, when the user
will press the ok button on the second form, i want to take all the the lines
of that header from the dataBase and write them into the dataGrid of the
first form. the problem i'm having is that i don't know how many checkboxes
will be checked, so i can just create variables, so what can i do to get the
lines of each header from the database and insert them to the dataGrid of the
first form?
I hope i explained my problem just enough to get some help...
Thanks,
Gidi.
 
G

Guest

This is a sorta typical 'delegate situition', heres a simple example

//Datagrid selection form, ONLY a ID and Checked data fields
public class DatagridForm : System.Windows.Forms.Form {

private System.Windows.Forms.DataGrid grdData;
private System.Windows.Forms.Button btnSelect;

GridItemSelected gridItemSelected;

public delegate void GridItemSelected(int id);

public DatagridForm(GridItemSelected gridItemSelected) {
InitializeComponent();

this.gridItemSelected = gridItemSelected;
this.btnSelect.Click += new System.EventHandler(this.SelectItem);
}

private void SelectItem(object sender, System.EventArgs e) {
if (gridItemSelected == null) {
return;
}
DataTable table = (DataTable)grdData.DataSource;
foreach(DataRow row in table.Rows) {
if (Convert.ToBoolean(row["Checked"])) {
gridItemSelected(Convert.ToInt32((row["ID"])));
}
}

}

//MainForm which fires on the datagrid form
public class MainForm : System.Windows.Forms.Form {
//...
private void btnSelectDetail_Click(object sender, System.EventArgs e) {
DatagridForm form = new DatagridForm(new
DatagridForm.GridItemSelected(this.GridItemSelected));
form.ShowDialog();
}

//This method is called for each of the checked data row in the grid form
void GridItemSelected(int id) {
Console.WriteLine(("[Selected]" + id);
}

//...
}

Altho the data gets passed back may vary, the idea is the same

Hope this helps
 

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