|
tims81 wrote: Thanks, but I still get the index out of range exception when calling the above code.
i can't use "GridView.ClearSelection(1, 1, true)" either as i am told that that method is inaccessible due to its protection level.
Aw, I overlooked the protected flag
In what event is this code running? Can you paste the entire eventhandler?
GridView.Sort(GridView.Columns[1], ListSortDirection.Descending);
GridView.Rows[0].Selected = true;
I are Troll
|
|
|
|
|
The entire event handler is kinda big with different sub methods but essentially i am running it from a button_click event handler.
|
|
|
|
|
I've tried this code to confirm that it works;
private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt = new DataTable("employee");
dt.Columns.Add("firstname");
dt.Columns.Add("lastname");
dt.Rows.Add("john", "doe");
dt.Rows.Add("johnny", "walker");
dataGridView1.DataSource = dt;
}
void HandleClick(object sender, EventArgs e)
{
dataGridView1.ClearSelection();
if (dataGridView1.Rows.Count > 0)
dataGridView1.Rows[0].Selected = true;
}
This code fills a DataGridView, and focus is on the last cell of the last row when it finishes loading. After clicking Button1, it clears the entire selection, optionally selecting the first row.
tims81 wrote: The entire event handler is kinda big with different sub methods
Can you take a look at the Exception that you're getting, or post it here? It should contain the name of the method that caused the exception, maybe we can find something there
Is the event SelectionChanged used in the code? Could other events be triggered while you're doing work in the button-handler?
I are Troll
|
|
|
|
|
My bad, the selectionChanged event was causing an error. fixed that. now calling
GridView.Select();
GridView.ClearSelection();
GridView.Rows[0].Selected = true;
but it still only shows the first row selected but then continues from the original row when using the arrow keys. did your code still work after trying a sort operation like:
GridView.Sort(GridView.Columns[1], ListSortDirection.Descending); ?
|
|
|
|
|
tims81 wrote: but it still only shows the first row selected but then continues from the original row when using the arrow keys. did your code still work after trying a sort operation like:
You're right! It showed the highlighting on the correct row, but the focus-rectangle for keyboard-input was still on the last row. In order to "force" the correct focus, I changed the example-code to this;
private void Form1_Load(object sender, System.EventArgs e)
{
DataTable dt = new DataTable("employee");
dt.Columns.Add("firstname");
dt.Columns.Add("lastname");
dt.Rows.Add("john", "doe");
dt.Rows.Add("johnny", "walker");
dataGridView1.DataSource = dt;
dataGridView1.Sort(dataGridView1.Columns[1], ListSortDirection.Descending);
}
void HandleClick(object sender, EventArgs e)
{
dataGridView1.ClearSelection();
if (dataGridView1.Rows.Count > 0)
{
dataGridView1.Rows[0].Selected = true;
dataGridView1.CurrentCell = dataGridView1.Rows[0].Cells[0];
}
}
Hope this helps
I are Troll
|
|
|
|
|
It works now! That's so awesome. Thank you so much for your help, I owe you one!!!
|
|
|
|
|
You're welcome
I are Troll
|
|
|
|
|
Pelase help,
I want to write some data to Contactless Smartcard Mifare DESFIRE ev1,
using Smartcard writer/reader is ACS ACR122.I use C# to write the application
This is a example of data that want to write :
1. Name
2. DOB
3. etc
My question is : how to create the file structure of the data?
Regard,
Mashudi
thanks
|
|
|
|
|
have you found any solution by now ?
|
|
|
|
|
Hello I would like to ask how to I get this error
below here is the code
Dim con As New OleDb.OleDbConnection<br />
Dim inc As Integer<br />
Dim MaxRows As Integer<br />
Dim ds As New DataSet<br />
Dim da As OleDb.OleDbDataAdapter<br />
Dim sql As String<br />
<br />
<br />
<br />
Private Sub Sampler_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<br />
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _<br />
"Data Source = c:\Sadsign.mdb"<br />
con.Open()<br />
<br />
sql = "SELECT * FROM Names"<br />
da = New OleDb.OleDbDataAdapter(sql, con)<br />
<br />
<br />
da.Fill(ds, "contacts")<br />
'con.Close()<br />
'MaxRows = ds.Tables("contacts").Rows.Count<br />
'inc = -1<br />
<br />
End Sub
my error is in "da.fill" command and the error is
"IErrorInfo.GetDescription failed with E_FAIL(0x80004005)"
Thanks,
dfan23
|
|
|
|
|
Try putting square brackets around Names . 'Name' is a reserved word in Access. 'Names' may be, I'm not sure. I don't use Access for any database work.
If your database does not have any security setup in it in Access, you may also want to chagne the connection string to read:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Sadsign.mdb;User Id=admin;Password=;
If you DO have security setup, look at these[^] examples of connection strings.
|
|
|
|
|
Hello,
Thanks for the immediate response sir.
Now I know that Name/Names are not valid as variable names.
If would you mine sir I would like to ask how to add a new row
to my database then how to update the changes made into the database
Thanks,
dfan23
|
|
|
|
|
try this:
Dim con As New OleDb.OleDbConnection
Dim inc As Integer
Dim MaxRows As Integer
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim dt As DataTable
Private Sub Sampler_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ds = new DataSet("dataSet");
dt = new DataTable("Contacts");
ds.Tables.Add(dt);
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source = c:\Sadsign.mdb"
con.Open()
sql = "SELECT * FROM Names"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(dt, "contacts")
'con.Close()
'MaxRows = ds.Tables("contacts").Rows.Count
'inc = -1
End Sub
|
|
|
|
|
Hello sir,
I would like to thanks for the immediate response
but I still have error when I try your code
I still got this error
"Object is not an ADODB.RecordSet or an ADODB.Record. Parameter name: adodb"
I'm a bit confuse now or anything coz I think the codes is right
by the way sir I am using visual studio team system 2008
and microsft access 2007 as my database.
Thanks,
dfan23
|
|
|
|
|
OK. use this code:
Private Sub Sampler_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ds = New DataSet("dataSet")
dt = New DataTable()
ds.Tables.Add(dt)
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source = c:\Sadsign.mdb"
con.Open()
sql = "SELECT * FROM [Names]"
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(dt)
'con.Close()
'MaxRows = ds.Tables("contacts").Rows.Count
'inc = -1
End Sub
seems that "Names" is a reserved keyword. Hence the error.
|
|
|
|
|
Hello,
Thanks for the immediate response sir.
Now I know that Name/Names are not valid as variable names.
If would you mine sir I would like to ask how to add a new row
to my database then how to update the changes made into the database.
I have a code for adding a new row but still got error in updating it.
The Error is "Syntax error in INSERT INTO statement."
below here is my code:
da = New OleDb.OleDbDataAdapter(sql, con)
cb = New OleDb.OleDbCommandBuilder(da)
Dim newRow As DataRow
newRow = ds.Tables("employeeTable").NewRow
ds.Tables("employeeTable").Rows.Add(newRow)
newRow.Item("Position") = comboPosition.Text
newRow.Item("Last_Name") = txtLastName.Text
newRow.Item("First_Name") = txtFirstName.Text
da.Update(ds, "employeeTable")
Thanks,
dfan23
|
|
|
|
|
dfan23 wrote: Now I know that Name/Names are not valid as variable names.
Is your problem sorted? then rate the answer.
dfan23 wrote: If would you mine sir I would like to ask how to add a new row
to my database then how to update the changes made into the database.
I have a code for adding a new row but still got error in updating it.
Looks to me that you should read some textbooks for this...or atleast google how to work with datatables.
here is an nice link that i learnt from... guess u would like it too. http://www.dotnetfunda.com/articles/article131.aspx[^]
|
|
|
|
|
Hello, sorry for reposting this
Thanks for the immediate response sir.
Now I know that Name/Names are not valid as variable names.
If would you mine sir I would like to ask how to add a new row
to my database then how to update the changes made into the database.
I have a code for adding a new row but still got error in updating it.
The Error is "Syntax error in INSERT INTO statement."
below here is my code:
<pre>da = New OleDb.OleDbDataAdapter(sql, con)
cb = New OleDb.OleDbCommandBuilder(da)
Dim newRow As DataRow
newRow = ds.Tables("employeeTable").NewRow
ds.Tables("employeeTable").Rows.Add(newRow)
newRow.Item("Position") = comboPosition.Text
newRow.Item("Last_Name") = txtLastName.Text
newRow.Item("First_Name") = txtFirstName.Text
da.Update(ds, "employeeTable")</pre>
Thanks,
dfan23
|
|
|
|
|
Buddy there can be many things wrong here.
You haven't created a commandbuilder here.
commandbuilder can only work when there is a primary key in the database.
Why don't you read some books before posting these kind of questions here. These are one of the most basic questions available in any textbook which teach VB.net with SQL
any code which works with sql will work with msAccess too except for using a OleDbConnection instead of SqlConnection
|
|
|
|
|
Hello,
thanks for the help I kindly appreciate your suggestions,
I have read some vb.net books but some are using the drag and
drop system , but I wanted to try also coding all the connections.
Thanks again,
dfan23
|
|
|
|
|
|
Hello,
Thanks for your help and suggestion.
|
|
|
|
|
I have a VB.Net application that references a DLL written in VC++. This is a critical application and must run. Sporadically (about once a week) the application generates a message with the app name as title with the text "<app> has encountered a problem and needs to close..." and the buttons "Debug" and "Close" at the bottom. The problem here is that I need to know that the application has generated the message so that I can kill it and restart it immediately. I have tried to send a message to an auxilliary application that monitors the main app, but since it is in a timed loop, the message is sent even if the debug message is shown, so as far as the aux. app is concerned, everything is just fine.
I have disabled the JIT debug script and tried everything I know of to get around this. It seems that Microsoft insists on giving you a message whether you want it or not.
Sitting and waiting for the error to occur is not an option and the log files I have put into the program don't tell me what stopped it. The DLL is the source of the problem.
What I need is a way of disabling the runtime debug message so that the program just dies, so it can be detected and restarted, or barring that, a way of having a separate program detect that the main program has entered into this state, so it can be killed and restarted.
Note: If you are going to mention the painfully obvious and tell me that I should fix the DLL, trust me - I've tried and will keep trying. You'll be wasting your time and mine. I just need an interim solution that will keep the application running. TIA
|
|
|
|
|
|
He said not to mention the painfully obvious
I know the language. I've read a book. - _Madmatt
|
|
|
|