I am basically doing a search against the binding source so that i can set the active row. Can some give me assistance. I get set the binding source with current position. One I recieve the binding source position , i can set the active row with the value of the binding source position. For some reason it keep giving me the position 0
private void UserSearchUltraTextEditor_ValueChanged_1(object sender, EventArgs e) { string userNameToFind = UserSearchUltraTextEditor.Text; this.ultraGrid1.ActiveRow = null; foreach (var user in this.userDataSet.ApprovedPersonnel) { if (user.UserName.StartsWith(userNameToFind, true, System.Globalization.CultureInfo.CurrentCulture)) { BindingSource.Position = this.BindingSource.IndexOf(user); // This line is setting the position to 0 //everytime which is false this.ultraGrid1.ActiveRow = this.ultraGrid1.Rows[BindingSource.Position]; break; } } }
I'm only guessing here, but my guess is that the BindingSource.IndexOf function is not finding the user you are passing it to the list because the BindingSource doesn't contain the actual DataRow objects from the dataset. The BindingSource probably uses a wrapper object of some kind, like a DataRowView.
I did a quick fix with ling and use the index off of the list. Do you think this change is valid?
private void UserSearchUltraTextEditor_ValueChanged_1(object sender, EventArgs e) { string userNameToFind = UserSearchUltraTextEditor.Text; this.ultraGrid1.ActiveRow = null; var UserDataSetRecords = (from uDataSetRow in this.userDataSet.ApprovedPersonnel select uDataSetRow).ToList(); foreach (var user in UserDataSetRecords) { if (user.UserName.StartsWith(userNameToFind, true, System.Globalization.CultureInfo.CurrentCulture)) { this.ultraGrid1.ActiveRow = this.ultraGrid1.Rows[UserDataSetRecords.IndexOf(user)]; break; } } }
If you use the ActiveRowAppearance, then you don't have to do anything. The grid will keep track of the ActiveRow and when you set a new ActiveRow the appearance on the old ActiveRow will be cleared.
If you are selecting the row, then you have to de-select the old row.
If you are applying an appearance to the row, then you have to clear the appearance on the previous row.
This works, but i am not for sure if this what you meant by clearing the previous row to remove the row appearance, also read the comments below, for some reason the ultratextbox is empty if still jumps into the startwith case below. I am not for sure why
private void UserSearchUltraTextEditor_ValueChanged(object sender, EventArgs e)
{
string userNameToFind = UserSearchUltraTextEditor.Text;
this.ultraGrid1.ActiveRow = null;
//Deselect row appeearance back color
if(string.IsNullOrEmpty(UserSearchUltraTextEditor.Text))
this.ultraGrid1.Rows[lastRowIndex].Selected = false;
this.ultraGrid1.Rows[0].Selected = false;
}
foreach (UltraGridRow row in this.ultraGrid1.Rows.GetFilteredInNonGroupByRows())
string user = row.Cells["Username"].Text;
if (user.StartsWith(userNameToFind, true, System.Globalization.CultureInfo.CurrentCulture))
//For some reason if userNameToFind = "" or string.empty it jumps into this case. I am not for sure why. so i added the if statement below to not go into the case below if userNameToFind == ""
if (userNameToFind != string.Empty)
this.ultraGrid1.ActiveRow = row;
this.ultraGrid1.ActiveRow.Selected = true;
lastRowIndex = this.ultraGrid1.ActiveRow.Index;
break;
Okay, so you are setting the ActiveRow and you are also selecting the row. That's a bit redundant, but there's nothing necessarily bad about that.
You could use use the ActiveRowAppearance, as I said, and then you would not have to worry about clearing the previous row's appearance.
Or you could use grid.Selected.Rows.Clear to clear the previously selected rows.
Thanks again
This works perfectly by clearing the rows. I had a duhhhhhhhh moment lol. Trying to clear the last couple of requirements with the simple stuff. The simple stuff is killing me lol. But yeah this is the best option below.
this
.ultraGrid1.Selected.Rows.Clear(); // This works
I also tried using the ActiveRowAppearance, that was still keeping the all rows selected with color appearance. I am not for sure why
KeithDudley said:I also tried using the ActiveRowAppearance, that was still keeping the all rows selected with color appearance. I am not for sure why
Were you also still setting the Selected? If you use ActiveRowAppearance, then you don't need to select (or clear the selection) on any rows.
You might need to disable selection, too, by setting SelectTypeRow to None.