Looping thru one column
-
Hello all I have a datagrid that i need to loop through the column called TABLE_NAME and use all the cells that end with the word "Data". ANY help is appreciated. I have included a small snippet: Dim dt As DataTable = acc_connect.GetSchema("tables") GridView1.DataSource = dt GridView1.SelectAll() For Each r As DataGridViewCell In GridView1.SelectedCells Dim str As String = r.Value.ToString Dim i As Integer = str.IndexOf("Data") If Not i = -1 Then But this in no way works, thanks in advance!!!
-
Hello all I have a datagrid that i need to loop through the column called TABLE_NAME and use all the cells that end with the word "Data". ANY help is appreciated. I have included a small snippet: Dim dt As DataTable = acc_connect.GetSchema("tables") GridView1.DataSource = dt GridView1.SelectAll() For Each r As DataGridViewCell In GridView1.SelectedCells Dim str As String = r.Value.ToString Dim i As Integer = str.IndexOf("Data") If Not i = -1 Then But this in no way works, thanks in advance!!!
Hi,
zchwllms wrote:
But this in no way works
that's not informative; you should explain what it does and how that differs from what you want, otherwise we have to guess. There is a String.EdsWith() method that will interest you. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Hi,
zchwllms wrote:
But this in no way works
that's not informative; you should explain what it does and how that differs from what you want, otherwise we have to guess. There is a String.EdsWith() method that will interest you. :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
Yes, sorry about that, well as of right now I am getting the column heading as the value and what I is whatever is in the cell on that column. I was looking for somthing like: for each r as string in datagridview.column if r.endswith("Data") then 'the rest of my code will go here next thanks again
-
Yes, sorry about that, well as of right now I am getting the column heading as the value and what I is whatever is in the cell on that column. I was looking for somthing like: for each r as string in datagridview.column if r.endswith("Data") then 'the rest of my code will go here next thanks again
Hi, a DataGridViewCell holds an Object, so the Value property returns that object. All objects inherit ToString() method from class Object, it simply returns the type string. So whatever your DGVC is actually holding, you should either override its ToString() to return real content, or provide (and use) another way to retrieve its representation (some classes have a GetTect method for this). :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Hi, a DataGridViewCell holds an Object, so the Value property returns that object. All objects inherit ToString() method from class Object, it simply returns the type string. So whatever your DGVC is actually holding, you should either override its ToString() to return real content, or provide (and use) another way to retrieve its representation (some classes have a GetTect method for this). :)
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
Thank you for elaborating, I am pretty new to this whole thing. But my question is still how do I loop through these cells(only in one column) to actually get the content of the cell into a variable string. I understand the logic I am just not sure on how to actually pull the content out of the cell for usage. thanks, zach
-
Thank you for elaborating, I am pretty new to this whole thing. But my question is still how do I loop through these cells(only in one column) to actually get the content of the cell into a variable string. I understand the logic I am just not sure on how to actually pull the content out of the cell for usage. thanks, zach
Hi, I haven't used DataGridView myself, here is my best guess: - DGV has a property called Rows, this holds all the rows, so you can iterate them with a
foreach (DataGridViewRow row in myDGV.Rows) {...}
- a DataGridViewRow has a property called Cells, this holds all the cells of that row, as in one array; you can apply an index to them as inrow.Cells[i];
- with the above, you could access all the cells that belong to a single column, provided you now the index of that column. If you have to find out that index, well DGV has a property called Columns, this holds all the column descriptions (not the data, just metadata). I hope and think that would put you on track. :)Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Hi, I haven't used DataGridView myself, here is my best guess: - DGV has a property called Rows, this holds all the rows, so you can iterate them with a
foreach (DataGridViewRow row in myDGV.Rows) {...}
- a DataGridViewRow has a property called Cells, this holds all the cells of that row, as in one array; you can apply an index to them as inrow.Cells[i];
- with the above, you could access all the cells that belong to a single column, provided you now the index of that column. If you have to find out that index, well DGV has a property called Columns, this holds all the column descriptions (not the data, just metadata). I hope and think that would put you on track. :)Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips: - make Visual display line numbers: Tools/Options/TextEditor/... - show exceptions with ToString() to see all information - before you ask a question here, search CodeProject, then Google
-
Hello all I have a datagrid that i need to loop through the column called TABLE_NAME and use all the cells that end with the word "Data". ANY help is appreciated. I have included a small snippet: Dim dt As DataTable = acc_connect.GetSchema("tables") GridView1.DataSource = dt GridView1.SelectAll() For Each r As DataGridViewCell In GridView1.SelectedCells Dim str As String = r.Value.ToString Dim i As Integer = str.IndexOf("Data") If Not i = -1 Then But this in no way works, thanks in advance!!!
How about this: Create a dataview filtering on column TABLE_NAME like %data. Then just loop through this dataview. Guy
You always pass failure on the way to success.
-
How about this: Create a dataview filtering on column TABLE_NAME like %data. Then just loop through this dataview. Guy
You always pass failure on the way to success.