|
So, is it sorted now?
if yes, then rate the answer and mark it as solution to your problem.
|
|
|
|
|
hello,
A big 5 is really nice for you sir.
Thanks,
dfan23
|
|
|
|
|
u r welcome. and please stop calling me sir. we all have gone through this phase and i am just returning the favor of someone else who helped me in the past.
cheers!!
|
|
|
|
|
Hello,
now I can move on the next part of coding
for the system I'm planning to create.If ever I cant figured out again
my problem going to post it again here.
Thanks again for the help.
Thanks,
dfan23
|
|
|
|
|
In my application I am loading rows of data into a gridview object and then performing an internal sort (by code) for one of the columns. After that I select (by code) the top row. This seems to work as the top row in the gridview is selected by the cursor. However when I subsequently use the up/down arrow keys on the keyboard to navigate up and down the gridview, the cursor starts off at the original row that was selected BEFORE the sorting instead of the top row as selected by code. How do I get the software to continue from the top row as selected?
|
|
|
|
|
|
Thanks for the advise. But whenever i call DataGridView.ClearSelection() i get the error message telling me that the index is out of range even if the count of DataGridView.SelectedRows.Count is equal to 1 at that point.
All i am really doing is
GridView.Sort(GridView.Columns[1], ListSortDirection.Descending);
GridView.Rows[0].Selected = true;
//at this point DataGridView.SelectedRows.Count is equal to 1.
// if i call DataGridView.ClearSelection() at this point i will get an error
|
|
|
|
|
From what event are you running the code?
Try this code from a button;
GridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
GridView.ClearSelection();
I are Troll
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|