![]() Label1.Text = DGV.Name & " Column " & e.ColumnIndex.ToString & " Row " & e.RowIndex.ToString & " value = " & DGV(e.ColumnIndex, e.RowIndex).Value.ToString Private Sub DGV1_CellClick(sender As Object, e As DataGridViewCellEventArgs) Handles DGV1.CellClick, DGV2.CellClick, DGV3.CellClick, DGV4.CellClickĭim DGV As DataGridView = DirectCast(sender, DataGridView) Combined with the code shown here, you could deal with any DGV in the same way (you are right in using column names rather than indexes - a necessity with multiple possible varieties being used) ' Form1 with There may be a need (not shown here) to cycle through cells in a row, or columns in a DGV etc and that is quite simple. ![]() I do not understand your question, but you mention multiple DataGridViews (hopefully you have datasources as datatables?)Īnyway, here is a stand alone example that will allow differentiation between various DataGridViews, and based on user selection, displays a Label with identity info on User selection. 'All columns that must contain numerical values are added here in case the cell contains text.ĪryMsg(i) = AryMsg(i) & ": Must be a number." 'All columns that must contain text are added here by their column header.ĪryMsg(i) = AryMsg(i) & " is """ & (c.Value) & """." 'All other entries are allowed null values and will display the following message. 'All columns that must contain numerical values are added here by their column header.ĮlseIf sender.Columns(i).HeaderText = "Lat Shift" Or sender.Columns(i).HeaderText = "Lon Shift" Or sender.Columns(i).HeaderText = "Lat Multiplier" Or sender.Columns(i).HeaderText = "Lon Multiplier" ThenĪryMsg(i) = AryMsg(i) & ": Cannot be blank." If sender.Columns(i).HeaderText = "Map Name" ThenĪryMsg(i) = AryMsg(i) & ": The Map must have a name." 'All columns that must contain text are added here by their column header with the appropriate message. Is there a better way than this? Can you create a list with the same attribute, in this case columns that are numeric or columns that must have a value, and just reference it once? For Each c As DataGridViewCell In "sender.Columns(i).HeaderText = "Lat Shift" Or" and this would become quite lengthy if you wanted to add several columns. The variable X isn't so bad and I think I have seen a way to do it with a variable but I'm using I would have thought there was another way like e.g. ![]() If x = "Frog" or X = "Snake" or X = "Bird" or X = "Horse" or X = "Dog" etc. The specific line is where the same object or variable can have multiple different values and you end up writing it over and over again and you may need to do it more than once. I had considered an array but if there is already a way then why bother. ![]() What I think is a problem is that you repeat the same thing time after time and I believe that there must be a simplified way of doing this that I don't know about. I'm referencing the column header text to avoid using column indexes as they are specific to location and Datagridview which would not be good for multiple uses. I don't know if it's possible but I was trying to make the code generic so that it can be used for multiple DataGridViews in the same application or copied to another application and used with few changes. I have a DataGridView for which I have created validating code and message boxes that work. ![]()
0 Comments
Leave a Reply. |