Returning data with a bound listbox
-
I have a form with a listbox bound to a sql database. I use a dataset to fill the listbox. I need to have it multiselect and return the data selected. Trying to test this in a messagebox it returns dataview objects and mot the data selected. Any ideas Mike
-
I have a form with a listbox bound to a sql database. I use a dataset to fill the listbox. I need to have it multiselect and return the data selected. Trying to test this in a messagebox it returns dataview objects and mot the data selected. Any ideas Mike
-
I have a form with a listbox bound to a sql database. I use a dataset to fill the listbox. I need to have it multiselect and return the data selected. Trying to test this in a messagebox it returns dataview objects and mot the data selected. Any ideas Mike
Thanks for that reply, I see that and have ammended my code as such, I am making headway though. I can now return the corect amount of selected items but it only returns the top item that many times. Any ideas from virewing my code.
//Method used to add data to newly inserted rows
private void AddData(System.Data.DataRow row, System.Data.DataRow row2)
{
StringBuilder strb = new StringBuilder();
string str1 = "";object missing = System.Type.Missing; if ((checkBox1.Checked) || (checkBox2.Checked)) { MessageBox.Show("There are no rows to insert"); } else { //Add data from data row to the table Microsoft.Office.Interop.Word.Selection selection = Globals.ThisDocument.Application.Selection; int count = Globals.ThisDocument.Tables.Count; if (selection.Tables.Count > 0) { Microsoft.Office.Interop.Word.Row newRow = Globals.ThisDocument.Tables\[count\].Rows.Add(ref missing); newRow.Range.Font.Bold = 0; newRow.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; newRow.Cells\[2\].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; newRow.Cells\[1\].Range.Text = row\["HSActionPlanSubHeader"\].ToString(); foreach (DataRowView itm in this.itemDescriptionListBox.SelectedItems) { //newRow.Cells\[2\].Range.Text = row2\["ItemDescription"\].ToString(); str1 = row2\["ItemDescription"\].ToString(); strb.Append(str1); } newRow.Cells\[2\].Range.Text = strb.ToString(); } else { MessageBox.Show("Cursor must be within a table.", "Actions Pane", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
-
Thanks for that reply, I see that and have ammended my code as such, I am making headway though. I can now return the corect amount of selected items but it only returns the top item that many times. Any ideas from virewing my code.
//Method used to add data to newly inserted rows
private void AddData(System.Data.DataRow row, System.Data.DataRow row2)
{
StringBuilder strb = new StringBuilder();
string str1 = "";object missing = System.Type.Missing; if ((checkBox1.Checked) || (checkBox2.Checked)) { MessageBox.Show("There are no rows to insert"); } else { //Add data from data row to the table Microsoft.Office.Interop.Word.Selection selection = Globals.ThisDocument.Application.Selection; int count = Globals.ThisDocument.Tables.Count; if (selection.Tables.Count > 0) { Microsoft.Office.Interop.Word.Row newRow = Globals.ThisDocument.Tables\[count\].Rows.Add(ref missing); newRow.Range.Font.Bold = 0; newRow.Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft; newRow.Cells\[2\].Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight; newRow.Cells\[1\].Range.Text = row\["HSActionPlanSubHeader"\].ToString(); foreach (DataRowView itm in this.itemDescriptionListBox.SelectedItems) { //newRow.Cells\[2\].Range.Text = row2\["ItemDescription"\].ToString(); str1 = row2\["ItemDescription"\].ToString(); strb.Append(str1); } newRow.Cells\[2\].Range.Text = strb.ToString(); } else { MessageBox.Show("Cursor must be within a table.", "Actions Pane", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
I did not analyze your code, however this struck me:
surfluds wrote:
foreach (DataRowView itm in this.itemDescriptionListBox.SelectedItems) { //newRow.Cells[2].Range.Text = row2["ItemDescription"].ToString(); str1 = row2["ItemDescription"].ToString(); strb.Append(str1); }
itm is enumerating a collection, however you don't use it anywhere??? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
I have a form with a listbox bound to a sql database. I use a dataset to fill the listbox. I need to have it multiselect and return the data selected. Trying to test this in a messagebox it returns dataview objects and mot the data selected. Any ideas Mike
-
I did not analyze your code, however this struck me:
surfluds wrote:
foreach (DataRowView itm in this.itemDescriptionListBox.SelectedItems) { //newRow.Cells[2].Range.Text = row2["ItemDescription"].ToString(); str1 = row2["ItemDescription"].ToString(); strb.Append(str1); }
itm is enumerating a collection, however you don't use it anywhere??? :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).