hello there,
I'm using a vb.net and using for displaying a record into system.windows.forms.datagridview "datagridview".. my problem is i want to set unfocus the grid "remove the highlighted cell there." i just want to remove the highlighted cell on load and put it on clicking the grid. is this possible?? please help.
Thanks in advance.
Loading

AlanRank #669 · 3.6K reputationPosted Aug 13, 2008, 12:29 PM EDT
If DataGridView1 is your DGV, then try putting this line in your Form1_Load:
DataGridView1.SelectedRows(0).Selected = False
Leslie Parba9 reputationPosted Aug 13, 2008, 1:39 PM EDT
Parameter name: index" this is my code.
Private Sub LoadToGrid()
Dim ConnString As String = CurrentFacade.OnlineConnectionString
Dim SQLString As String = "SELECT ID, LabelDesc, LengthDescription, FontSize, XCoor, YCoor, FontName, FontColor, case TextJustication when 1 then 'Left' when 2 then 'Center' when 3 then 'Right' end as TextJustification, BlacklistDictionary FROM CustomField_C"
Dim SqlDataAdapter1 As New SqlDataAdapter(SQLString, ConnString)
Dim DataSet1 As New DataSet()
SqlDataAdapter1.Fill(DataSet1, "CustomField_c")
grd1.DataSource = DataSet1.Tables("CustomField_c")
// this is to hide the first colurm. which is the ID
grd1.Columns(0).Visible = False
grd1.SelectedRows(0).Selected = False
End Sub
AlanRank #669 · 3.6K reputationPosted Aug 13, 2008, 2:20 PM EDT
Assuming you're calling the LoadToGrid() method from Form_Load, the error message suggests that no rows are selected at that stage. So the first row must get selected just after the form loads.
If that's the case, then I think I'd try handling the Form's GotFocus event (or possibly the Activated event) instead and put that line in the eventhandler:
Private Sub Form1_GotFocus(sender as Object, e as EventArgs) _
Handles Form1.GotFocus
grd1.SelectedRows(0).Selected = False
End Sub
From memory, I don't think this event shows up in the VS Properties box so you'll just have to paste it in.
Leslie Parba9 reputationPosted Aug 13, 2008, 2:33 PM EDT
AlanRank #669 · 3.6K reputationPosted Aug 13, 2008, 2:52 PM EDT
Leslie Parba9 reputationPosted Aug 13, 2008, 3:01 PM EDT
Ryan AlfordRank #1,411 · 1.2K reputationPosted Aug 14, 2008, 6:14 AM EDT
ex...
If DataGridView1.Rows.Count > 0 Then
DataGridView1.SelectedRows(0).Selected = false
Leslie Parba9 reputationPosted Aug 14, 2008, 7:17 AM EDT