|
Since responses have ended, I will post elsewhere. Thanks for the replies.
|
|
|
|
|
let's say i have two columns,one called area and second called city .i want to get all the cities when i choos a Specific area .
i use with datatable and i don't know how to Formulate an sql Query.it's suppose to be like that:
string areaName = DropDownList1.Items[DropDownList1.SelectedIndex].ToString().Trim();
DataRow[] city = dt.Select("city_name where area='"+areaName+"'");
for (int i = 0; i < city.Count<DataRow>(); i++)
{
DropDownList2.Items.Add(city[i]["city_name"].ToString());
}
|
|
|
|
|
I can't quite tell what you are trying to do there, but (dt is a DataTable, right?) you could try:
dt.DefaultView.RowFilter = "area=" + areaname ;
DropDownList2.DataSource = dt.DefaultView ;
Edit: Here's a full working example.
System.Data.DataRow dr ;
// Define a State table
System.Data.DataTable state = new System.Data.DataTable("State");
state.Columns.Add(new System.Data.DataColumn("ID",typeof(int)));
state.Columns.Add(new System.Data.DataColumn("Name",typeof(string)));
// Add some rows
dr = state.NewRow() ;
dr [ "ID" ] = 1 ;
dr [ "Name" ] = "Arizona" ;
state.Rows.Add ( dr ) ;
dr = state.NewRow() ;
dr [ "ID" ] = 2 ;
dr [ "Name" ] = "California" ;
state.Rows.Add ( dr ) ;
// Set the first ComboBox to display the table
this.comboBox1.DataSource = state.DefaultView ;
this.comboBox1.DisplayMember = "Name" ;
// Define a City table
System.Data.DataTable city = new System.Data.DataTable("State");
city.Columns.Add(new System.Data.DataColumn("ID",typeof(int)));
city.Columns.Add(new System.Data.DataColumn("State",typeof(int)));
city.Columns.Add(new System.Data.DataColumn("Name",typeof(string)));
// Add some rows
dr = city.NewRow() ;
dr [ "ID" ] = 1 ;
dr [ "State" ] = 1 ;
dr [ "Name" ] = "Phoenix" ;
city.Rows.Add ( dr ) ;
dr = city.NewRow() ;
dr [ "ID" ] = 2 ;
dr [ "State" ] = 1 ;
dr [ "Name" ] = "Tucson" ;
city.Rows.Add ( dr ) ;
dr = city.NewRow() ;
dr [ "ID" ] = 3 ;
dr [ "State" ] = 2 ;
dr [ "Name" ] = "San Diego" ;
city.Rows.Add ( dr ) ;
dr = city.NewRow() ;
dr [ "ID" ] = 4 ;
dr [ "State" ] = 2 ;
dr [ "Name" ] = "Los Angeles" ;
city.Rows.Add ( dr ) ;
// Set the second ComboBox to display the table
this.comboBox2.DataSource = city.DefaultView ;
this.comboBox2.DisplayMember = "Name" ;
// Add a SelectedIndexChanged handler
this.comboBox1.SelectedIndexChanged += delegate ( object sender , System.EventArgs e )
{
System.Data.DataRowView item = this.comboBox1.SelectedItem as System.Data.DataRowView ;
city.DefaultView.RowFilter = "State=" + item [ "ID" ] ;
return ;
} ;
// Select the first State
this.comboBox1.SelectedIndex = 0 ;
modified 14-Jan-13 9:49am.
|
|
|
|
|
i have two DropDownList and i want that if i choose from the first DropDownList valu(i mean area) automaticly in the second DropDownList i will have all the cities in that area.
|
|
|
|
|
Trap the change event on the 1st combo and filter the datasource of the second combo based on the selected item of the 1st combo.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
By learning what an event is, how to wire it up and how to deal with the result. All this depends on your UI, ASP/SL-WPF/Winforms are all different.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
someone already help me from anther site ,my problem now is only if i press on some button(even if the button do not doing anyting) i see the new data in my second DropDownList.how can i get the data Immediate in the second DropDownList when i change something in the first DropDownList ?
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
string areaName = DropDownList1.Items[DropDownList1.SelectedIndex].ToString().Trim();
DataRow[] city = dt.Select("area='" + areaName + "'");
for (int i = 0; i < city.Count<DataRow>(); i++)
{
DropDownList2.Items.Add(city[i]["city_name"].ToString());
}
}
|
|
|
|
|
Just set the DefaultView's RowFilter. Done.
modified 14-Jan-13 9:51am.
|
|
|
|
|
i dont understand to what do you mean
|
|
|
|
|
You have a DataTable with the cities, right? It has a DefaultView property. You set it as the DataSource of the control. Possibly have to set the DisplayMember property as well. And when the value in the other control changes, set the RowFilter value of this one.
|
|
|
|
|
the solution was to change in the propoty of the first DropDownList the autopostback to true
|
|
|
|
|
I need to translit the documents, translit from cyrillic letters to latin letters.
and I need to make my program to work with as many documents as it possible, and huge document, may be a document with 500 pages....
So, I'm thinking different ways to implement it to work as efficient as possible...
any advices?
|
|
|
|
|
I would have thought using Binary Reader and Writer would be extremely tortuous for this - you would have to parse the document file(s) by hand
Why not look at a level of abstraction 'above' that .. this is an interop/RCW method of interacting with a Word Doc ... http://code.msdn.microsoft.com/office/CSAutomateWord-f422cae5[^] but it may not be good for 500 pages - you'd have to loop through all pages getting the text, (possibly) creating a new document with the translated text.
There are other ways to read/write Word documents - Read Document Text Directly from Microsoft Word File[^] for instance
'g'
|
|
|
|
|
Hello,
My code is trying to delete IExplorer history from the registry! The typed URLs are stored in a checked listbox, i can delete one value at a time both in the registry and from the checked listbox but when i try deleting multiple items at a time it doesn't work? here is the code
private void Delete_Click(object sender, EventArgs e)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\TypedURLs", true);
string[] v = key.GetValueNames();
string[] t = new string[v.Length];
int count = checkedListBox1.Items.Count;
for (int i = 0; i < v.Length - 1; i++)
{
t[i] = (string)key.GetValue(v[i]);
if(t[i] == (string)checkedListBox1.SelectedItem)
{
key.DeleteValue(v[i]);
}
}
for ( int i = count; i > 0; i--)
{
if (checkedListBox1.CheckedItems.Contains(checkedListBox1.Items[i - 1]))
{
checkedListBox1.Items.RemoveAt(i - 1);
}
}
}
|
|
|
|
|
Hi,
if(t[i] == (string)checkedListBox1.SelectedItem)
SelectedItem is one item, use SelectedItems to get all selected items:
if (checkedListBox1.SelectedItems.Contains(t[i]))
Add also this in the constructor:
checkedListBox1.SelectionMode = SelectionMode.MultiExtended;
checkedListBox1.SelectionMode = SelectionMode.MultiSimple;
Hope this helps.
In some cases, my signature will be longer than my message...
<em style="color:red"> <b>ProgramFOX</b></em> ProgramFOX
modified 14-Jan-13 11:57am.
|
|
|
|
|
Still doesn't seem to have worked? Any other ideas please?
|
|
|
|
|
Erol2309 wrote: Any other ideas please?
I updated my answer.
In some cases, my signature will be longer than my message...
<em style="color:red"> <b>ProgramFOX</b></em> ProgramFOX
|
|
|
|
|
What does "doesn't work" mean? Ate you getting exceptions? What happens when you step over the code?
|
|
|
|
|
Well it means that when there are all the items in the checkedlistbox selected and i press the delete button they get deleted from the checkedlistbox but not from the registry...i cand only delete values from the registry one at a time and only when there are more than 2 entries..
|
|
|
|
|
I Checked your code for deleting the multiple items from the registry and it works fine, if doesnt work means check the checkbox comparison operations.
Also I doubt on the action performed inside the second for loop, the checkBox content is checked against its own value was it v[i] or t[i] arrays?
Jibesh V P
|
|
|
|
|
If you had stepped over your code, you would have seen what the problem is. Basically, you're iterating over one list of values, and you're getting one single value from the other list to compare it to. Try iterating over the selected items from the list box as well, and do your comparison in there.
Now, a more important point is that your comparison code is using terrible variable names. I ended up getting confused by your t and v variables.
|
|
|
|
|
Hi,
I am trying to trite a small app that acceses internet browser history on IExplorer using its registry. Somehow i cannot delete the URLs that have been viewed.
note: After accesing the registry i store the data in a checkedlistbox. Any help?
private void Delete_Click(object sender, EventArgs e)
{
RegistryKey key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\TypedURLs", true);
string[] v = key.GetValueNames();
string[] t = new string[v.Length];
int count = checkedListBox1.Items.Count;
for (int i = 0; i < v.Length - 1; i--)
{
t[i] = (string)key.GetValue(v[i]);
if(t[i] == (string)checkedListBox1.SelectedItem)
{
key.DeleteValue(t[i]);
}
}
for ( int i = count; i > 0; i--)
{
if (checkedListBox1.CheckedItems.Contains(checkedListBox1.Items[i - 1]))
{
checkedListBox1.Items.RemoveAt(i - 1);
}
}
|
|
|
|
|
Um:
for (int i = 0; i < v.Length - 1; i--)
{
t[i] = (string)key.GetValue(v[i]);
i-- ? Really?
We all do it at some point...
If you get an email telling you that you can catch Swine Flu from tinned pork then just delete it. It's Spam.
|
|
|
|
|
wow....that was just to stupid....sorry...thanks alot!!! I really apreciate
|
|
|
|