Returning selected row index after filtering
-
I'm a total begginer. I work as a aplication tester with C# developers. They use DevExpress controls, but I don't have a licence for it, so I've tried to create UserControl that will work simmilar as one of the UserControls in that application that was made in Developer Express. this is the problem: I have 2 textboxes and one DataGridView. These 2 tb-s are used for filtering DGV (one of 2 columns). I've bound it to the DataSet with 3 colums, but I don't want to show them all, just these 2. What I want is to return third, hidden column. Problem is, I used BindingSource to filter DataGridRows, so it will show me only those rows that contain written data in those textboxes (eg. let's say column1 is FIRST NAME, Column2 is SECOND NAME, textbox1 filters names, and textbox2 filters SECOND NAMES). So It's like: private void tbFirstName_TextChange(object sender, EventArgs e) { string filter = "FirstName like '" + tbFirstName.Text + "%'"; bsUsers.Filter = filter; bsUsers is BindingSource, binded to DataSet, and it's DataSoruce for DataGridView .... When I select filtered DataGridRow, it's index in BindingSource is not equal to that in DataSet, becouse every time i filter, it generates new indexes starting from 0. How do I know on what row I am in DataSet. I want to know what ID is for what user, but I don't want ID column to be visible in DataGridView. I hope you've understand. Thanx in advance...
-
I'm a total begginer. I work as a aplication tester with C# developers. They use DevExpress controls, but I don't have a licence for it, so I've tried to create UserControl that will work simmilar as one of the UserControls in that application that was made in Developer Express. this is the problem: I have 2 textboxes and one DataGridView. These 2 tb-s are used for filtering DGV (one of 2 columns). I've bound it to the DataSet with 3 colums, but I don't want to show them all, just these 2. What I want is to return third, hidden column. Problem is, I used BindingSource to filter DataGridRows, so it will show me only those rows that contain written data in those textboxes (eg. let's say column1 is FIRST NAME, Column2 is SECOND NAME, textbox1 filters names, and textbox2 filters SECOND NAMES). So It's like: private void tbFirstName_TextChange(object sender, EventArgs e) { string filter = "FirstName like '" + tbFirstName.Text + "%'"; bsUsers.Filter = filter; bsUsers is BindingSource, binded to DataSet, and it's DataSoruce for DataGridView .... When I select filtered DataGridRow, it's index in BindingSource is not equal to that in DataSet, becouse every time i filter, it generates new indexes starting from 0. How do I know on what row I am in DataSet. I want to know what ID is for what user, but I don't want ID column to be visible in DataGridView. I hope you've understand. Thanx in advance...
Hi Tomy, I would suggest following. If you are having only one table in dataset then use datatable instead. Dont use BindingSource directly assign datatable to DataGridView as DataSource. Apply the filter directly to DataTable.Defaultview. This way any selected row from DataGridView will have direct link to underlying DataTable. You can also add a DataColumn as Boolean type to apea in DataGridView as checkbox which your user can select and you can easily track it for further action. Hope this helps. Difficult - > Challenging, this simple replacement made me take my life little easy;)
-
Hi Tomy, I would suggest following. If you are having only one table in dataset then use datatable instead. Dont use BindingSource directly assign datatable to DataGridView as DataSource. Apply the filter directly to DataTable.Defaultview. This way any selected row from DataGridView will have direct link to underlying DataTable. You can also add a DataColumn as Boolean type to apea in DataGridView as checkbox which your user can select and you can easily track it for further action. Hope this helps. Difficult - > Challenging, this simple replacement made me take my life little easy;)
I like the idea, and I'll try it, but I still don't know how to get current row from DataTable, and value for specific column .... I think that DataSet.tblTable.DefaultView can do the same as DataTable.DefaultView ... And there is RowFilter, but I still don't know how to retrieve exact column value from selected row.
-
I'm a total begginer. I work as a aplication tester with C# developers. They use DevExpress controls, but I don't have a licence for it, so I've tried to create UserControl that will work simmilar as one of the UserControls in that application that was made in Developer Express. this is the problem: I have 2 textboxes and one DataGridView. These 2 tb-s are used for filtering DGV (one of 2 columns). I've bound it to the DataSet with 3 colums, but I don't want to show them all, just these 2. What I want is to return third, hidden column. Problem is, I used BindingSource to filter DataGridRows, so it will show me only those rows that contain written data in those textboxes (eg. let's say column1 is FIRST NAME, Column2 is SECOND NAME, textbox1 filters names, and textbox2 filters SECOND NAMES). So It's like: private void tbFirstName_TextChange(object sender, EventArgs e) { string filter = "FirstName like '" + tbFirstName.Text + "%'"; bsUsers.Filter = filter; bsUsers is BindingSource, binded to DataSet, and it's DataSoruce for DataGridView .... When I select filtered DataGridRow, it's index in BindingSource is not equal to that in DataSet, becouse every time i filter, it generates new indexes starting from 0. How do I know on what row I am in DataSet. I want to know what ID is for what user, but I don't want ID column to be visible in DataGridView. I hope you've understand. Thanx in advance...
Well, I've browsed around a bit and this is what I've found: private void button1_Click(object sender, EventArgs e) { int ID; testDS.tblTestRow selectedRow; selectedRow = (testDS.tblTestRow)((DataRowView)bsTest.Current).Row; ID = selectedRow.ID; MessageBox.Show(ID.ToString()); } And other thing that filters these rows: private void txtName_textchange(object sender, EventArgs e) { string filter = "NAME like '" + txtName.Text + "%'"; bsTest.Filter = filter; bsTest is BindingSource, and testDS is DataSet (could be single table - DataTable, doesen't matter) - but I don't know how to do it without BindingSource.