|
Hello all,
I am using a DataGridView bound to a DataTable. How can I allow the user to type a letter on the keyboard and have the DataGridView change current row the first occurrence of a letter. For example, a column in the table is Lastname, so typing ‘S’ would bring you to the first Lastname that starts with an S.
I gather the best way would be to search the DataTable then use the result to set the DataGridView.
Note: column to search does not have a primary key as last name is not always unique.
Thanks in advance,
KCI
Get to work!
|
|
|
|
|
Use the LIKE operator from SQL. You might also be interested in the SOUNDEX function, that you can use to locate similar-sounding names
--edit--
JimSchor wrote: For example, a column in the table is Lastname, so typing ‘S’ would bring you to the first Lastname that starts with an S.
Aw, a new SQL-query on each keypress, my first advice wouldn't be very efficient. That means filtering the data that you already have - sort a View [^] that's based on your DataTable [^].
I are Troll
modified on Tuesday, September 29, 2009 5:01 PM
|
|
|
|
|
If you use a BindingSource to bind to your DataGridView , this (MSDN)[^] might help.
If not, this[^] article has some interesting ideas. It uses a DataGrid , not a DataGridView but there is a very similar example on MSDN for a DataGridView , I just cannot find it right now.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for the advice, but I have tried these. Let me be a little more specific.
So far, I gather using dt.DefaultView may be the way to go since it does not require a PrimaryKey. And to note I am not using a bindingsource. My goal is to search the existing in memory rowset and not require another trip back and forth to the SQL server.
Here is a code snippet I tried, but it returns -1:
ds.Tables["Students"].DefaultView.Sort = "LastName";
int intRow = ds.Tables["Students"].DefaultView.Find("S%");
I have also tried this, but it returns zero rows:
ds.Tables["Students"].DefaultView.Sort = "LastName";
DataRowView[] drv = ds.Tables["Students"].DefaultView.FindRows("[LastName] LIKE 'S'");
Thanks,
KCI
Get to work!
modified on Wednesday, September 30, 2009 8:42 AM
|
|
|
|
|
Hello,
I have a question about the best way to Insert/Update a table that has around 117 fields.
I can create my own Insert/Update commands or use the CommandBuilder. Both of those need Parameters setup, but that's a lot of fields to setup.
Maybe I am missing something and there is a solution that I am not seeing.
Would it be easier to have a foreach loop and create the Insert/Update commands along with the parameters?
Any thoughts?
Thanks,
Chuck
|
|
|
|
|
I like to keep my tables a little less broad. Perhaps some normalization is in order?
Other than possibly using a DataAdapter you're stuck with creating the parameters. What would a for loop gain you?
only two letters away from being an asset
|
|
|
|
|
castrand1 wrote: I have a question about the best way to Insert/Update a table that has around 117 fields.
Well, there's two things here.
1 - the number of fields does not change the code
2 - your database design is dreadful to non existant.
castrand1 wrote: Both of those need Parameters setup, but that's a lot of fields to setup.
Yes, sometimes a programmer needs to actually write code. Terrible, it's true. Your core issue is your broken table design, however.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
castrand1 wrote: a table that has around 117 fields.
After putting in about 30 fields, did it occur to you that this may not be the best design??
|
|
|
|
|
Hello All,
I appreciate all the comments and yes, that database is bad and needs to be redesigned.
Let me explain what the table holds and maybe I could get some insight in how to best redesign it.
The table stores information about ships. These ships are of a tanker type ship, ones that hold crude oil, vegetable oil, etc.
Of all the fields in the table, most of the fields describe the ship, such as, dimensions, draughts, capacities, deadweights, etc. So, every ship will have unique values in the fields.
There are several fields that are relational. Hull Types, Owners, Classifications, Status, etc, other than that, all the other fields would hold unique values.
Thank you for your help,
Chuck
|
|
|
|
|
You can start by putting fields related to a subject about the ship in their own tables. Such as a ships navigation equipment goes in one table, hull information in another, engine information in another, ... You're not going to need every pipece of information about a ship all at once, so it's better break the data down into smaller logical blocks of related information and keep each block in its own table.
|
|
|
|
|
Dave,
Thank you for your suggestions with this issue. It made a lot of sense and I don't know why I did not see it. I have not really run into an issue of this type. So, I split the table into 6 different tables, each with less than 20 fields each, much more manageable.
Again, thank you.
Chuck
|
|
|
|
|
Hey,
I have a couple of link buttons and I am trying to get them to open a page in a new window. I know how to do this with a normal link, but I also have some very simple code behind that I need to run (Set a session variable).
I've tried to add attributes to the linkbutton by doing lnkBtnEnterprise.Attributes.Add("Target", "_blank");
but that doesnt seem to do anything. Let me know if you have any suggestions. Thanks for your time.
protected void lnkBtnEnterprise_Click(object sender, EventArgs e)
{
lnkBtnEnterprise.Attributes.Add("Target", "_blank");
Session["Owner"] = 1;
Response.Redirect("~/SampleDashboardDetails.aspx");
}
JM
|
|
|
|
|
I also tried putting lnkBtnEnterprise.Attributes.Add("Target", "_blank"); on the page load event.
|
|
|
|
|
First, this won't do anything for you. You are applying an attribute to the link then immediately redirecting to another page.
Second, attributes are case sensitive, target should be lowercase.
only two letters away from being an asset
|
|
|
|
|
I have absolutely no clue, is this ASP.NET?
|
|
|
|
|
Yes, it is ASP.NET. I was trying to open the page using C# and w/o javascript. I've spent all day trying to figure it out to no avail.
When I do the lnkBtnEnterprise.Attributes.Add("target", "_blank"); and click the button on the page, I get an error of "Microsoft JScript runtime error: Object expected"
|
|
|
|
|
WE have an ASP.NET forum. Posting in the C# forum leaves people trying to figure out if you're writing a web app, which is often less obvious than it was in this case.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
OK, but its a C#.Net question, is it not? Thats why I thought this forum was more appropriate.
|
|
|
|
|
The code might be in C# but the concepts are either Web Development or ASP.Net, either of which would, in my opinion, be better homes for your question.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
OK, I'll post the question over there. Thanks anyway for your help.
|
|
|
|
|
I found a solution. I ended up changing the link buttons to links and passed a variable through the link, then grabbed the variable and stored it to the session variable I was using in a Page_PreInit function.
Send it from first page:
<asp:HyperLink ID="lnkEnterprise" runat="server" NavigateUrl="~/SampleDashboardDetails.aspx?Owner=1" Target="_blank">Enterprise Details</asp:HyperLink>
Receive on second page:
protected void Page_PreInit(Object sender, EventArgs e)
{
Session["Owner"] = Request.QueryString["Owner"];
}
Thanks for your help guys.
|
|
|
|
|
<asp:LinkButton ID="lbtnValidRules" runat="server" Text="Validation Rules" OnClientClick="window.open('ValidationRules.aspx', 'ValidRules', 'width=1100,height=800,status=yes'); return false;">
</asp:LinkButton>
this is how I do
|
|
|
|
|
Seriously, WTF. Session, Response??? This doesn't give you a clue??
only two letters away from being an asset
|
|
|
|
|
Barely, sounds like webcrap, I'm not into that at all
|
|
|
|
|
btw did you onevote me for not having a clue?
|
|
|
|